jstl基础代码

来源:互联网 发布:python网络数据采集 编辑:程序博客网 时间:2024/06/16 04:16
[java] view plaincopy
  1. <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>  
  2. <%@ page contentType="text/html;charset=utf-8" %>  
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>  
  5. <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>  
  6. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
  7. <%  
  8. String path = request.getContextPath();  
  9. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  10. %>  
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  12. <html>  
  13.   <head>  
  14.     <base href="<%=basePath%>">  
  15.       
  16.     <title>My JSP 'MyJsp.jsp' starting page</title>  
  17.       
  18.     <meta http-equiv="pragma" content="no-cache">  
  19.     <meta http-equiv="cache-control" content="no-cache">  
  20.     <meta http-equiv="expires" content="0">      
  21.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  22.     <meta http-equiv="description" content="This is my page">  
  23.     <!--  
  24.     <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">  
  25.     -->  
  26.   </head>  
  27.     
  28.   <body>  
  29.     This is my JSP page. <br>  
  30.       
  31.     <c:out value="first"/>  
  32.     <c:out value="${header['user-agent']}"></c:out><br>  
  33.     <c:out value="${p}">default001</c:out><br>  
  34.     <c:out value="hellojsp2.0"/><br>  
  35.     <c:out value="${2+4}"/><br>  
  36.     <c:out value="${param.data}" default="no data"/><br>  
  37.     <c:out value="</p>have speical" escapeXml="true"/><br>  
  38.       
  39.     <c:set var="number" value="${1+1}" scope="session"/>  
  40.     <c:out value="${number}"/><br>  
  41.     ${number}************  
  42.      
  43.     <c:set var="number1" scope="page" >  
  44.     (1+1)  
  45.     </c:set>  
  46.     <c:remove var="number1" scope="page"/>   
  47.    <c:out value="${number1}" default="removed"/><br>  
  48.      
  49.     <c:catch var="catchname">  
  50.     <%  
  51.     String ef="no number";  
  52.     int i=Integer.parseInt(ef);  
  53.       
  54.     %>  
  55.       
  56.     </c:catch>  
  57.     ${catchname }  
  58.       
  59.     <c:if test="${param.username=='admin'}" var="condition" scope="page">  
  60.     (if test)user***admin  
  61.     </c:if>  
  62.     ${condition }  
  63.     <br>  
  64.     <c:choose>  
  65.         <c:when test="${param.username=='admin'}">  
  66.         user****admin  
  67.         </c:when>  
  68.         <c:when test="${param.username=='superadmin'}">  
  69.         user****superadmin  
  70.         </c:when>  
  71.           
  72.         <c:otherwise>  
  73.         user****no permission  
  74.         </c:otherwise>  
  75.     </c:choose><br>  
  76.     <%  
  77.     String[] atts=new String[5];  
  78.     for(int i=0;i<atts.length;i++){  
  79.         atts[i]="array"+i;  
  80.         System.out.println(atts[i]);  
  81.     }  
  82.     session.setAttribute("arraytest",atts);  
  83.      %>  
  84.     <c:forEach items="${arraytest}" var="at">  
  85.         <c:out value="${at}"/><br>  
  86.     </c:forEach>  
  87.     <%  
  88.     //ArrayList<String> alist = new ArrayList<String>();  
  89.     List<String> alist = new ArrayList<String>();  
  90.     for(int i=0;i<atts.length;i++){  
  91.         alist.add("arraylist"+i);  
  92.     }  
  93.     session.setAttribute("alist",alist);  
  94.       
  95.     Set<String> settest = new HashSet<String>();  
  96.     for(int i=0;i<atts.length;i++){  
  97.         settest.add("hashset"+i);  
  98.     }  
  99.     session.setAttribute("hashset",settest);  
  100.       
  101.     Map<String,String> hashmap = new HashMap<String,String>();  
  102.     for(int i=0;i<atts.length;i++){  
  103.         hashmap.put("key"+i,"value"+i);  
  104.           
  105.     }  
  106.     session.setAttribute("hashmap",hashmap);  
  107.       
  108.     ArrayList<Object> doublearraylist = new ArrayList<Object>();  
  109.     for(int i=0;i<atts.length;i++){  
  110.         doublearraylist.add(atts);  
  111.     }  
  112.     session.setAttribute("doublearraylist",doublearraylist);  
  113.       
  114.     ArrayList<Object> doublearraylisthash = new ArrayList<Object>();  
  115.     for(int i=0;i<atts.length;i++){  
  116.         doublearraylisthash.add(hashmap);  
  117.     }  
  118.     session.setAttribute("doublearraylisthash",doublearraylisthash);  
  119.       
  120.       
  121.     //Map<?,?> hashtableproperties  = System.getProperties();  
  122.     //Set<?> settest2 = hashtableproperties.entrySet();  
  123.     //Iterator<?> itror = settest2.iterator();  
  124.     //while(itror.hasNext()){  
  125.     //String keystr =(String)itror.next();  
  126.     //System.out.println("%%%%%%%%%"+keystr);  
  127.     //}  
  128.    Properties p = new Properties();  
  129.    p.setProperty("propertieskey","propertiesvalue");  
  130.     session.setAttribute("properties",p);  
  131.       
  132.      %>  
  133.     <c:forEach items="${alist}" var="at">  
  134.         <c:out value="${at}"/><br>  
  135.     </c:forEach>  
  136.     <c:forEach items="${hashset}" var="at">  
  137.         <c:out value="${at}"/><br>  
  138.     </c:forEach>  
  139.     <c:forEach items="${hashmap}" var="at">  
  140.         <c:out value="${at.key}"/>::::::::<c:out value="${at.value}"/><br>  
  141.     </c:forEach>  
  142.     --------------double loop start----------<br>  
  143.     <c:forEach items="${doublearraylist}" var="at">  
  144.         <c:forEach items="${at}" var="at1">  
  145.             <c:out value="${at1}"/><br>  
  146.         </c:forEach>  
  147.     </c:forEach>  
  148.     --------------double loop end----------<br>  
  149.       
  150.      --------------double loop hasharraylist start----------<br>  
  151.     <c:forEach items="${doublearraylisthash}" var="at">  
  152.         <c:forEach items="${at}" var="at1">  
  153.             <c:out value="${at1.key}"/>&&&&&&&&&&&&6<c:out value="${at1.value}"/><br>  
  154.         </c:forEach>  
  155.     </c:forEach>  
  156.     --------------double loop hasharraylist end----------<br>  
  157.       
  158.      --------------properties start----------<br>  
  159.     <c:forEach items="${properties}" var="at1">  
  160.         <c:out value="${at1.key}"/>@@@@@properties@@@@@@@<c:out value="${at1.value}"/><br>  
  161.     </c:forEach>  
  162.     --------------properties end----------<br>  
  163.       
  164.     --------------step start----------<br>  
  165.     <c:forEach items="${arraytest}" var="at1" begin="1" end="4" step="2">  
  166.         <c:out value="${at1}"/><br>  
  167.     </c:forEach>  
  168.     --------------step end----------<br>  
  169.       
  170.     <%  
  171.     int[] intarray = new int[10];  
  172.     for(int i=0;i<10;i++){  
  173.     intarray[i]=i;  
  174.     }  
  175.     session.setAttribute("intarray",intarray);  
  176.      %>  
  177.     <c:forEach items="${intarray}"  var="item" varStatus="s">  
  178.     <c:if test="${s.count%2==0}"><font color="blue"></c:if>  
  179.     <c:if test="${s.count%2==1}"><font color="green"></c:if>  
  180.     <c:out value="${item}"/>  
  181.     index*****<c:out value="${s.index}"/>  
  182.     count*****<c:out value="${s.count}"/>  
  183.     first*****<c:out value="${s.first}"/>  
  184.     last*****<c:out value="${s.last}"/><br>  
  185.       
  186.     </font>  
  187.     </c:forEach>  
  188.      <%  
  189.        
  190.        
  191.      //<!--<c:import url="import.txt" var="c" scope="session" />-->  
  192.      //<!-- <c:import url="http://www.google.cn/music/homepage">  
  193.         //<c:param name="hl" value="zh-CN"></c:param>  
  194.         //<c:param name="tab" value="wU"></c:param>  
  195.       //</c:import>-->  
  196.       //<!-- <c:redirect url="http://java.sun.com" >  
  197.       //</c:redirect>-->  
  198.        
  199.        
  200.      %>  
  201.          
  202.       
  203.     <c:forTokens items="1,2,5,7,8,56,tytr,;76gh,7,,87" delims="," var="as">  
  204.         <c:out value="${as}"></c:out><br>  
  205.     </c:forTokens>  
  206.      
  207.     <fmt:formatNumber value="12" pattern="0.00000" ></fmt:formatNumber>  
  208.       
  209.     <jsp:useBean id="now" class="java.util.Date"></jsp:useBean>  
  210.     <fmt:formatDate  value="${now}" pattern="yyyy-MM-dd"     />  
  211.       
  212.     <fmt:setBundle basename="/resources/app" var="app"/>  
  213.     <fmt:message key="dbname" bundle="${app}"/>  
  214.     <fmt:message key="app.name" bundle="${app}"/>  
  215.     <fmt:bundle basename="../resources/app">  
  216.         <fmt:message key="app.name" />  
  217.     </fmt:bundle>  
  218.       
  219.     <sql:setDataSource  
  220.     url="jdbc:postgresql://localhost/mydb"  
  221.     driver="org.postgresql.Driver"  
  222.     user="postgres"  
  223.     password="19810101"  
  224.     var="mydatasource"  
  225.     scope="session"  
  226.     />  
  227.       
  228.     <sql:query var="student" dataSource="${mydatasource}">  
  229.     select * from student order by stuno  
  230.     </sql:query>  
  231.     <table border="1" bordercolor="#cc2211">  
  232.     <tr >  
  233.     <td>stuno</td>  
  234.     <td>stuname</td>  
  235.     <td>score</td>  
  236.     </tr>  
  237.     <c:forEach var="row" items="${student.rows}">  
  238.     <tr>  
  239.         <td><c:out value="${row.stuno}"/></td>  
  240.         <td><c:out value="${row.stuname}"/></td>  
  241.         <td><c:out value="${row.stuscore}"/></td>  
  242.     </tr>  
  243.     </c:forEach>  
  244.     </table>  
  245.     good   
  246.     <c:out value="${fn:length('8886776')}"/>  
  247.     <%  
  248.       
  249.         //<c:set var="score" value="90"></c:set>  
  250.     ////<c:set var="sno" value="1001"></c:set>  
  251.    //// <c:set var="stardate" value="${now}" ></c:set>  
  252.     //<sql:transaction dataSource="${mydatasource}">  
  253.         //<sql:update>  
  254.             //////update student set stuscore=?,startdate=?  where stuno=to_number(?,'99999')  
  255.             //<sql:param value="${score}"></sql:param>  
  256.             //<sql:dateParam value="${stardate}" type="timestamp"></sql:dateParam>  
  257.             //<sql:param value="${sno}"></sql:param>  
  258.           
  259.         //</sql:update>  
  260.     //</sql:transaction>  
  261.       
  262.     %>  
  263.       
  264.       
  265.       
  266.       
  267.       
  268.       
  269. </body>  
  270. </html>   
0 0
原创粉丝点击