小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

常用代碼提示 - zgsony的日志 - 網(wǎng)易博客

 Ethan的博客 2011-03-17

常用代碼提示

Java記錄 2008-12-22 10:56:55 閱讀118 評論0   字號: 訂閱

 


  前端表達(dá)式:  EL 與jstl


如果EL表達(dá)式怎么解析不了呢?

     可以在JSP頁面中加入這行代碼

<%@ page isELIgnored="false" %> 試試吧.

JSP中引入包:

 <%@ page import="com.ddwl.struts.*" %> 

     也面的值必須存放起來放在session   或者applcation 中  

   尋找順序:page---request-session-application
     ${username}; 顯示普通值
     ${cus.account},${cus.password}  顯示javabean的值 cus為一個(gè)類的對象    account  password為屬性。
      ${cus.phones[0]}, ${cus.phones[1]},顯示集合  phones為arraylist類型

     集合內(nèi)的javabean 內(nèi)容顯示:
         ${cuses[0].account}, ${cuses[0].password},                  ${cuses[1].account}, ${cuses[1].password}, 
  如果要拿到參數(shù)的值:
     如:<a href=p2.jsp?m=3&n=4> 
   在下一個(gè)頁面中要拿到m和n的值:
    參數(shù)m:${param.m}, 參數(shù)n:${param.n}
 
顯示cookie 的值:
response.addCookie(new Cookie("username",Tom));
則顯示頁面為:
 ${cookie.username.value}  顯示結(jié)果為:   Tom

JSTL   :
   顯示值輸出:
     <% session.setAttribute("msgs",Welcome,Session");
       session.setAttribute("score",67);

 %>
    ${msgs};
或:輸出值:  <c:out value="${msgs}" > </c:out>

條件控制:1.    <c:if test="${score>60}">
                及格
                </c:if>
           <c:if test="${score<60}">
           不及格
             </c:if>
2.條件控制
<c:choose>
 <c:when test="${score>90}">優(yōu)秀</c:when>
<c:when test="${score>80}">良好</c:when>
 <c:when test="${score>70}">一般</c:when>
<c:when test="${score>60}">及格</c:when>
 <c:when test="${score<60}">不及格</c:when>
<c:otherwise> 輸入錯(cuò)誤 </c:otherwise>     
</c:choose>

3.循環(huán)
 <c:forEach items="${books}" var="book">
   ${book}
 </c:forEach > 
   注:items 為sesion中存放的值    var 的值為變量名,將遍歷后的結(jié)果存放在book中       
 
 2.集合中有javabean循環(huán)輸出:
<c:forEach items="${books}" var="book">
   ${book.name},  ${book.price}
 </c:forEach >
3.javabean中有集合:
<c:forEach items="${books.name}" var="name">
   ${book.name},  ${book.price}
 </c:forEach >
books 中name 是集合
4. HashMap輸出:

  <c:forEach items="${hm}" var="content">
   ${content.key},  ${content.value};
 </c:forEach >

 


關(guān)于循環(huán)拿出數(shù)組的辦法:

public PageModel searchPaginated(String hql,Object[] params,int offset,int pagesize){

 String countHql=getCountQuery(hql);

   Query query =this.getSession().createQuery(countHql);
  
   if(params !=null && params.length>0){
    for(int i=0;i<params.length;i++){
     query.setParameter(i, params[i]);
    }


}

 

數(shù)據(jù)庫部分:常見sql 語句

 select * from t_user where id=#id#
insert into t_user values(null,#username#,#password#)
 update t_user set username=#username# ,password=#password#
   where id=#id#
 delete from t_user where id=#id#

 

 

 


隨機(jī)數(shù)字的生成:
    
     //  隨機(jī)產(chǎn)生lenght 個(gè)數(shù)字
         private String randomString(int length){
  long randomNumber = random(1,9999999999l);
  StringBuffer sb = new StringBuffer();
  sb.append(randomNumber);
  for(int i=0; i<length; i++){
   sb.append("0");
  }
  return sb.substring(0, length);
 }
 
 /**
  * 在begin和end之間產(chǎn)生一個(gè)隨機(jī)數(shù)
  * @param begin
  * @param end
  * @return
  */
 private long random(long begin,long end){
  long rtn = begin + (long)(Math.random() * (end - begin));
  if(rtn == begin || rtn == end){
   return random(begin,end);
  }
  return rtn;
 }

 

 

一。   等待后跳轉(zhuǎn)代碼:
5秒鐘后自動重定向
  <div id="num" >

  </div>
   <script type="text/javascript">
<!--
var leftTime=5000;
   function go() {
   document.getElementById("num").innerText=leftTime;
   leftTime-=1000;
   if(leftTime<=0){
    document.location.href="cart.jsp"
      }
    }
    setInterval(go,1000);
      
//-->
</script>

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多