昨天将以前在开发中经常使用的case_jsp2温习了一遍。以下为case_jsp2文档部分内容。仅供参考:
<c:out><c:remove>
- scope:
- Page PageScope
- Request RequestScope
- Session SessionScope
- Application ApplicationScope
- tag:
- commons:如<c:out>、<c:remove>、<c:catch>、<c:set>等
- condition:如<c:if><c:when>、<c:choose>、<c:otherwise>等
- url:如<c:import>、<c:redirect>和<c:url>等
- xml:如<xml:out>等
- ii8:如<fmt:timeZone>等
- sql:如<sql:query>、<sql:update>、<sql:transaction>等
- taglib:
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
- exercise:
- 1. no cache
- if (request.getProtocol().compareTo("HTTP/1.0") == 0)
- response.setHeader("Pragma", "no-cache");
- else if (request.getProtocol().compareTo("HTTP/1.1") == 0)
- response.setHeader("Cache-Control", "no-cache");
- response.setDateHeader("Expires", 0);
- 2. exception
- <%@ page contentType="text/html;charset=UTP-8" isErrorPage="true" %>
- Exception<%= exception %><br>
- Message<%= exception.getMessage() %><br>
- Localized Message<%= exception.getLocalizedMessage() %><br>
- Stack Trace<% exception.printStackTrace(new java.io.PrintWriter(out)); %>
- 3.pageContext
- pageContext.setAttribute("Name","mike");
- pageContext.setAttribute("Password","browser");
- <jsp:forward page="XXX.jsp"/>
- XXX.jsp:
- String Name = (String)pageContext.getAttribute("Name");
- String Password = (String)pageContext.getAttribute("Password");
- out.println("Name = "+Name);
- out.println("Password = "+ Password);
- 4.application
- application.setAttribute("Name","mike");
- application.setAttribute("Password","browser");
- <jsp:forward page="XXX.jsp"/>
- XXX.jsp:
- String Name = (String) application.getAttribute("Name");
- String Password = (String) application.getAttribute("Password");
- out.println("Name = "+Name);
- out.println("Password = "+ Password);
- 5.request
- submit form:
- <form action="request.jsp" method="Get">
- Name<input type="text" name="Name" size="20" maxlength="20"><br>
- Number<input type="text" name="Number" size="20" maxlength="20"><br><br>
- <input type="submit" value="submit">
- </form>
- request.jsp:
- getParameter("Name")<%= request.getParameter("Name") %><br>
- getParameter("Number")<%= request.getParameter("Number") %><br>
- getAttribute("Name")<%= request.getAttribute("Name") %><br>
- getAttribute("Number")<%= request.getAttribute("Number") %><br><br>
- getAuthType( )<%= request.getAuthType() %><br>
- getProtocol( )<%= request.getProtocol() %><br>
- getMethod( )<%= request.getMethod() %><br>
- getScheme( )<%= request.getScheme() %><br>
- getContentType( )<%= request.getContentType() %><br>
- getContentLength( )<%= request.getContentLength() %><br>
- getCharacterEncoding( )<%= request.getCharacterEncoding() %><br>
- getRequestedSessionId( )<%= request.getRequestedSessionId() %><br><br>
- getContextPath( )<%= request.getContextPath() %><br>
- getServletPath( )<%= request.getServletPath() %><br>
- getPathInfo( )<%= request.getPathInfo() %><br>
- getRequestURI( )<%= request.getRequestURI() %><br>
- getQueryString( )<%= request.getQueryString() %><br><br>
- getRemoteAddr( )<%= request.getRemoteAddr() %><br>
- getRemoteHost( )<%= request.getRemoteHost() %><br>
- getRemoteUser( )<%= request.getRemoteUser() %><br>
- getRemotePort( )<%= request.getRemotePort() %><br>
- getServerName( )<%= request.getServerName() %><br>
- getServerPort( )<%= request.getServerPort() %><br>
- set attribute:
- request.setAttribute("Name","mike");
- request.setAttribute("Password","browser");
- <jsp:forward page="XXX.jsp"/>
- XXX.jsp:
- String Name = (String) request.getAttribute("Name");
- String Password = (String) request.getAttribute("Password");
- out.println("Name = "+Name);
- out.println("Password = "+ Password);
- 6.param
- <form method="post" action="XXX.jsp">
- <input type="text" name="username" size="15" />
- <input type="password" name="password" size="15" />
- <input type="radio" name="sex" value="Male" checked/>
- <input type="radio" name="sex" value="Female" />
- <select name="old">
- <option value="10">10 - 20</option>
- <option value="20" selected>20 - 30</option>
- <option value="30">30 - 40</option>
- <option value="40">40 - 50</option>
- </select>
- <input type="checkbox" name="habit" value="Reading"/>
- <input type="checkbox" name="habit" value="Game"/>
- <input type="checkbox" name="habit" value="Travel"/>
- <input type="checkbox" name="habit" value="Music"/>
- <input type="checkbox" name="habit" value="Tv"/>>
- <input type="submit" value="submit"/>
- <input type="reset" value="reset"/>
- </form>
- XXX.jsp:
- ${param.username}</br>
- ${param.password}</br>
- ${param.sex}</br>
- ${param.old}</br>
- ${paramValues.habit[0]}
- ${paramValues.habit[1]}
- 7.foreach
- String atts[] = new String [5];
- atts[0]="hello";
- atts[1]="this";
- atts[2]="is";
- atts[3]="a";
- atts[4]="pen";
- request.setAttribute("atts", atts);
- <c:forEach items="${atts}" var="item" >
- ${item}</br>
- </c:forEach>
- <c:forEach items="${atts}" var="item" begin="1" end="4" step="2" >
- ${item}</br>
- </c:forEach>
- <c:forEach begin="1" end="10" var="item" >
- ${item}</br>
- </c:forEach>
- <c:forEach items="${atts}" var="item"varStatus="s">
- <h2><c:out value="${item}"/></h2>
- index${s.index}</br>
- count${s.count}</br>
- first${s.first}</br>
- last${s.last}</br>
- </c:forEach>
- 8.usebean
- <jsp:useBean id="myBean" scope="page" class="com.melet.SimpleBean"/>
- <jsp:setProperty name="myBean" property="name" value="${param.Name}" />
- <jsp:setProperty name="myBean" property="number" value="${param.Number}"/>
- Hi !
- <font color="red"><jsp:getProperty name="myBean" property="name" /></font>
- <font color="red"><jsp:getProperty name="myBean" property="number" /></font>
- <form name="form1" action="XXX.jsp" method="post" >
- <input type="text" name="name">
- <input type="text" name="number">
- <input type="submit" value="submit">
- <input type="reset" value="reset">
- </form>
- XXX.jsp:
- <jsp:useBean id="myBean" scope="page" class="tw.com.javaworld.CH8.SimpleBean"/>
- <jsp:setProperty name="myBean" property="*" />
- <jsp:getProperty name="myBean" property="name"/>
- <jsp:getProperty name="myBean" property="number"/>
- 9。if
- <c:if test="${param.user=='melet'}" var="result" scope="page">
- ${param.user}<br>
- </c:if>
- 10.choose
- <c:set var="username" value="melet" />
- <c:set var="passwd" value="123" />
- <c:choose>
- <c:when test="${username=='melet'}">
- input the username is right<br>
- </c:when>
- <c:when test="${passwd=='123'}">
- input the password is right<br>
- </c:when>
- <c:otherwise>
- input the info is error <br>
- </c:otherwise>
- </c:choose>
- 11.out
- <c:set var="username" value="melet" scope="page" />
- username"<c:out value="${username}" />"<br>
- <c:set var="passwd" scope="request">
- 123
- </c:set>
- password value:"<c:out value="${passwd}" />"<br>
- <c:set var="num" value="${1+1}" />
- <c:set var="num1">
- <c:out value="${1+1}" />
- </c:set>
- <c:set var="num2">
- 1+1
- </c:set>
- <c:out value="${num}" /><br>
- <c:out value="${num1}" /><br>
- <c:out value="${num2}" /><br>