开发视频后台时遇到的小知识


1.jstl标签的使用:

   (1)日期输出格式 yyyy-MM-dd HH:mm:ss
      <display:column  escapeXml="false" sortable="true" titleKey="videocomments.CreateTime">
         <fmt:formatDate value="${vcList.createTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss"/>
      </display:column>
  (2)display:table的一些属性
      <display:table name="editorcommendList.editorcommend" cellspacing="0" cellpadding="0" requestURI=""
           id="ucList" class="table" export="true" >
    <display:column   escapeXml="false" sortable="true" titleKey="editorcommend.orderid" >
        <c:out value="${ucList_rowNum}"/>显示当前行的行数
    </display:column>
   <display:column titleKey="table.op" style="width: 20%"  escapeXml="false" sortable="false" media="html" >
        <input type="button" οnclick="location.href='/edit.html?videoId=<c:out   value="${ucList.videoId}"/>&type=last'" style="margin-right: 5px"
        value="<fmt:message key="button.edit"/>"/>//在超连接时,两种表示videoId 的方法
        <input type="button" style="margin-right: 5px"
        οnclick="javascript:if(window.confirm('Are you sure')) location.href=
        '<c:url value="/commend.html?videoId=${ucList.videoId}&method=del"/>';"
        value="<fmt:message key="button.delete"/>"/>          
    </display:column>
 </display:table>

2.取yyyy-MM-dd HH:mm:ss格式的日期,其中月份和天不包含"0X"的情况
   <%
    String str= DateUtil.getDate(new Date()).substring(0,11);
    //String[] arr = str.split("-");
    String  year;
    String day;
    String m = String.valueOf(str.charAt(5));
    if(m.equals("0")){
        month= str.substring(6,7);
    }else{
       month = str.substring(5,7);
    }
    String d = String.valueOf(str.charAt(8));
    if(d.equals("0")){
        day= str.substring(9);
    }else{
         day = str.substring(8);
    }
    String year = str.substring(0,4);
   %>
 <c:set var="nian"><%=year%></c:set>
 <c:set var="ri"><%=day%></c:set>
 <c:set var="yue"><%=month%></c:set>

     <select name="year" size="1" id="">
        <c:forEach var="year" begin="2002" end="2008" step="1" >
           <option <c:if test="${year==nian}">selected</c:if>><c:out value="${year}"/></option>
        </c:forEach>
     </select>

3.字符转化为utf-8
     public static String urlEncoder(String str,boolean option) {
        try{
            return URLEncoder.encode(str,"utf-8");
        } catch (Exception e) {
            if(option) {
                return str;
            } else {
                return "";
            }
        }
    }

4.groupSearch的按钮的可用和不可用
<a href="group.html?type=0" οnclick="javascript:groupSearch.style.display='none';"><fmt:message key="auditingComments.heading"/></a> |
<a href="group.html?type=1" οnclick="javascript:groupSearch.style.display='none';"><fmt:message key="defaultComments.heading"/></a> |
<a href="group.html?type=<c:out value="${groupcommentsList.type}"/>&s=1" οnclick="javascript:groupSearch.style.display='';"><fmt:message key="group.comments.search"/></a>

5.用js判断文本域的长度
<html>
 <body>
  <form name = "testform">
   <!--<textarea name="A" cols="45" rows="2" >aaaa</textarea>
   <input type="button" onclick = "checkValid()" value= "提交">-->
   <textarea name="A" cols="45" rows="2" onKeyDown='if (this.value.length>4){event.returnValue=false}'>1</textarea>
   <input type="submit" value= "提交">
  </form>
 </body>
</html>
<script language="javascript">
function checkValid()
{
 var a = document.testform.A;
 
 if(a.value.length > 4)
 {
  alert("输入的备注框长度不能超过20个字符!");
  return false;
 }
 return true;
}
</script>

6.转码,从汉字到utf-8
native2ascii  1.properties>2.properties
7.批量删除
<c:set var="buttons">
    <c:choose>
        <c:when test="${videocommentsList.type == '0'}">
            <input type="button" οnclick="batchDel();" value="<fmt:message key="button.deletesome"/>"/>
        </c:when>
        <c:when test="${videocommentsList.type == '1'}">
            <input type="button" οnclick="batchDel();" value="<fmt:message key="relationVideo.order.batch.delete"/>"/>
        </c:when>
    </c:choose>
</c:set>
 function batchDel(){
    if(!checkRelationBox()){
     alert("please select a checkbox!");
    }else{
 if(window.confirm('Are you sure')) {
      document.batchForm.method.value = "batchDel";
         document.batchForm.p.value = 1;
         document.batchForm.submit();
     }
     }
    }

    function checkRelationBox() {
     var element = document.getElementsByName("commentsIdBox");
        for (i = 0; i < element.length; i++) {
            if(!element[i].checked){
                var temp = document.batchForm.auditedId.value;
                document.batchForm.auditedId.value = temp+"|"+element[i].value;
            }
        }
        return true;
    }

    在Controller里面有这样的方法
  public ModelAndView batchDel(HttpServletRequest req, HttpServletResponse res) {
        if (log.isDebugEnabled()) {
            log.debug("video  batch delete.");
        }
        String view=messageComments;
        int type = ServletRequestUtils.getIntParameter(req,"type",0);
        int commentId = ServletRequestUtils.getIntParameter(req,"commentId",0);
        int page = ServletRequestUtils.getIntParameter(req,"p",1);
        int[] commentsIdAll = ServletRequestUtils.getIntParameters(req,"commentsIdBox");
        String auditedId = ServletRequestUtils.getStringParameter(req,"auditedId","");
        String returnStr = commentsManager.videobatchDel(commentsIdAll);
        String[] audited_id = StringUtil.analyzeStr(auditedId,"|");
        if(type==0) {
            for(String currId : audited_id) {
                commentsManager.doChangeVideoComments(Integer.parseInt(currId),type);
            }
        }
        MessageSourceAccessor text = new MessageSourceAccessor(messageSource, req.getLocale());
        return new ModelAndView(messageComments,"retStr",text.getMessage(returnStr));
    }
   
    全选按钮
   <input type="checkbox" name="allbox1" value="checkAll" οnclick="checkTheAll(this)"/><fmt:message key="videocomments.check"/>
     function checkTheAll(theElement) {
        for (var i=0;i<document.batchForm.commentsIdBox.length;i++) {
            document.batchForm.commentsIdBox[i].checked = theElement.checked;
     }
    }


8.判断日期符合实际情况:

 

function checkDate(theElement,fieldname) {
    var s 
= theElement.value;
    var filter 
= /^((((1[6-9]|[2-9]d)d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]d|3[01]))|(((1[6-9]|[2-9]d)d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]d|30))|(((1[6-9]|[2-9]d)d{2})-0?2-(0?[1-9]|1d|2[0-8]))|(((1[6-9]|[2-9]d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    
if (filter.test(s)){
        
return true;
    }
else{
        alert(
"请输入一个合法的" + fieldname +"");
        theElement.focus();
        
return false;
    }

   }

    注意调用时的格式是 YYYY-MM-DD 或者月 日 可以是一位的等 建议提前处理好 符合YYYY-MM-DD格式 然后调用这个  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值