JSP设计

header和headerValues:  header 储存用户浏览器和服务端用来沟通的数据  例:要取得用户浏览器的版本,可以使用${header["User-Agent"]}。  另外在鲜少机会下,有可能同一标头名称拥有不同的值,此时必须改为使用headerValues 来取得这些值。 []与.运算符:     EL 提供.和[]两种运算符来存取数据。 当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用 []。 例如:         ${user.My-Name}应当改为${user["My-Name"] }     如果要动态取值时,就可以用[]来做,而.无法做到动态取值。例如:         ${sessionScope.user[data]}中data 是一个变量 变量:     EL存 取变量数据的方法很简单,例如:${username}。它的意思是取出某一范围中名称为username的变量。因为我们并没有指定哪一个范围的 username,所以它会依序从Page、Request、Session、Application范围查找。假如途中找到username,就直接回 传,不再继续找下去,但是假如全部的范围都没有找到时,就回传null。     属性范围在EL中的名称         Page         pageScope         Request         requestScope         Session         sessionScope         Application     applicationScope EL隐含对象:  1.与范围有关的隐含对象  与范围有关的EL 隐含对象包含以下四个: pageScope、requestScope、sessionScope 和applicationScope;  它们基本上就和JSP的pageContext、request、session和application一样;  在EL中,这四个隐含对象用来取得范围属性值,即getAttribute(String name).   例如:我们要取得session中储存一个属性username的值,可以利用下列方法:     session.getAttribute("username") 取得username的值,  在EL中则使用下列方法     ${sessionScope.username}    2.与输入有关的隐含对象  与输入有关的隐含对象有两个:param和paramValues,它们是EL中比较特别的隐含对象。    例如我们要取得用户的请求参数时,可以利用下列方法:     request.getParameter(String name)     request.getParameterValues(String name)  在EL中则可以使用param和paramValues两者来取得数据。     ${param.name}     ${paramValues.name} 其他隐含对象:  cookie  JSTL并没有提供设定cookie的动作,  例:要取得cookie中有一个设定名称为userCountry的值,可以使用${cookie.userCountry}来取得它。    header和headerValues  header 储存用户浏览器和服务端用来沟通的数据  例:要取得用户浏览器的版本,可以使用${header["User-Agent"]}。  另外在鲜少机会下,有可能同一标头名称拥有不同的值,此时必须改为使用headerValues 来取得这些值。  书上的例子: <c:forEach items="${pageContext.request.cookies}" var="c">
          &nbsp;&nbsp;<b><c:out value="${c.name}" /></b>:
          <c:out value="${c.value}" /><br>
        </c:forEach>
cookie:

javax.servlet.http
类 Cookie

java.lang.Object   javax.servlet.http.Cookie
包含getName和getValue方法
Example 8-3. Request information (reqinfo.jsp):
<%@ page contentType="text/html" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    <html>   <head>     <title>Request Info</title>   </head>   <body bgcolor="white">        The following information was received:     <ul>       <li>Request Method:          <c:out value="${pageContext.request[method]}" />       <li>Request Protocol:          <c:out value="${pageContext.request[protocol]}" />       <li>Context Path:          <c:out value="${pageContext.request.contextPath}" />       <li>Servlet Path:          <c:out value="${pageContext.request.servletPath}" />       <li>Request URI:          <c:out value="${pageContext.request.requestURI}" />       <li>Request URL:          <c:out value="${pageContext.request.requestURL}" />       <li>Server Name:          <c:out value="${pageContext.request.serverName}" />       <li>Server Port:          <c:out value="${pageContext.request.serverPort}" />       <li>Remote Address:          <c:out value="${pageContext.request.remoteAddr}" />       <li>Remote Host:          <c:out value="${pageContext.request.remoteHost}" />       <li>Secure:          <c:out value="${pageContext.request.secure}" />       <li>Cookies:<br>         <c:forEach items="${pageContext.request.cookies}" var="c">           &nbsp;&nbsp;<b><c:out value="${c.name}" /></b>:           <c:out value="${c.value}" /><br>         </c:forEach>       <li>Headers:<br>         <c:forEach items="${headerValues}" var="h">            &nbsp;&nbsp;<b><c:out value="${h.key}" /></b>:           <c:forEach items="${h.value}" var="value">             <br>             &nbsp;&nbsp;&nbsp;&nbsp;<c:out value="${value}" />           </c:forEach>           <br>         </c:forEach>     </ul>   </body> </html>
pageContext隐含对象对应于javax.servlet.jsp.PageContext型态之对象,
隐含对象都自动的被加入至pageContext中,您可以藉由它来取得与JSP相关的隐含对象对应之Servlet对象
request:请求作用域,就是客户端的一次请求。
Request对象代表了客户端的请求信息(如请求的来源、
cookies和请求相关的参数值等等),
主要用于接受客户端通过HTTP协议传送给服务器端的数据。
accessed through the implicit pageContext variable's request property.
The request property is an instance
of a class named javax.servlet.http.HttpServletRequest

 Properties for javax.servlet.http.HttpServletRequestProperty nameJava typeAccessDescriptionauthType StringReadThe name of the authentication scheme protecting the requestcharacterEncoding     StringReadThe request body character encoding, or null if unknowncontentLength     intReadThe request body length, or -1 if unknowncontentType     StringReadThe request body MIME typecontextPath     StringReadThe context path for the requestcookies     javax.servlet.http.Cookie[]ReadThe cookies received with the requestlocale     java.util.LocaleReadThe client's preferred localelocales     java.util.EnumerationReadA list of all client locales in order of preferencemethod     StringReadThe request method (e.g., GET, POST)protocol     StringReadThe protocol name and version, e.g., HTTP/1.1remoteAddr     StringReadThe client's IP addressremoteHost     StringReadThe client's hostname or IP address if not knownremoteUser     StringReadThe username used to make the request if the page is protected, otherwise nullrequestURI     StringReadThe request URI, e.g., /app/page.jsprequestURL     StringBufferReadThe request URL, e.g., http://server/app/page.jspscheme     StringReadThe scheme, e.g., http or httpsservletPath     StringReadThe context-relative path for the request, e.g., /page.jspserverName     StringReadThe name of the server the request was sent toserverPort     intReadThe port the request was sent tosecure     booleanReadtrue if the request was made over a secure channel (e.g., SSL)userPrincipal     java.security.PrincipalReadThe Principal representing the user making the request if the page is protected, otherwise null
对比代码:
<%
out.println("Protocol: " + request.getProtocol() + "<br>");
out.println("Scheme: " + request.getScheme() + "<br>");
out.println("Server Name: " + request.getServerName() + "<br>" );
out.println("Server Port: " + request.getServerPort() + "<br>");
out.println("Protocol: " + request.getProtocol() + "<br>");
out.println("Remote Addr: " + request.getRemoteAddr() + "<br>");
out.println("Remote Host: " + request.getRemoteHost() + "<br>");
out.println("Character Encoding: " + request.getCharacterEncoding() + "<br>");
out.println("Content Length: " + request.getContentLength() + "<br>");
out.println("Content Type: "+ request.getContentType() + "<br>");
out.println("Auth Type: " + request.getAuthType() + "<br>");
out.println("HTTP Method: " + request.getMethod() + "<br>");
out.println("Path Info: " + request.getPathInfo() + "<br>");
out.println("Path Trans: " + request.getPathTranslated() + "<br>");
out.println("Query String: " + request.getQueryString() + "<br>");
out.println("Remote User: " + request.getRemoteUser() + "<br>");
out.println("Session Id: " + request.getRequestedSessionId() + "<br>");
out.println("Request URI: " + request.getRequestURI() + "<br>");
out.println("Servlet Path: " + request.getServletPath() + "<br>");
out.println("Accept: " + request.getHeader("Accept") + "<br>");
out.println("Host: " + request.getHeader("Host") + "<br>"); 
out.println("Referer : " + request.getHeader("Referer") + "<br>"); 
out.println("Accept-Language : " + request.getHeader("Accept-Language") + "<br>"); 
out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding") + "<br>"); 
out.println("User-Agent : " + request.getHeader("User-Agent") + "<br>"); 
out.println("Connection : " + request.getHeader("Connection") + "<br>"); 
out.println("Cookie : " + request.getHeader("Cookie") + "<br>"); 


%>

转载于:https://my.oschina.net/lzwenme/blog/270842

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
从1999年开始,企业级Java风暴般席卷了整个Java编程社区,开发者们都已认识到它在构建分布式应用程序方面的潜力。而现在,JSPJavaServer Pages)继续协调网页设计者和程序员之间的工作,让他们共同创建动态网站。JSP基于特定的Java servlet技术而构建,用它可以更加轻松地开发动态Web应用程序,即使您是一位硬核程序员也无妨。 《JSP设计(第二版)》得到了彻底的修订和更新,包括了JSP规范1.2版本中的重大变化。它包括关于JSP Standard Tag Library(JSTL)的详细内容 —— JSTL是一组殷切加入的JSP元素规范,用于多数JSP应用程序中需要的任务。本书开篇阐述了JSP如何充分利用Java servlet来创建高效、可移植的Web应用程序。书中还展示了如何用Apache Tomcat服务器启动JSP,并详细讲述了JSP语法和功能、错误处理和调试、身份验证和个性化,以及如何将JSTL用于数据库访问、XML处理及国际化等。 本书可以满足两类想学习JSP的专业人士的不同需要:一类是网页设计师,他们对如何在网页中使用JSP元素很感兴趣;另一类是程序员,他们对JSP API极为关注,并关心如何在企业级应用程序中有效地使用JSP。如果你是后者,本书还将指导你研究一些更深入的课题,诸如用普通的Apache Struts MVC框架将servlet和JavaBeans与JSP集成在一起等。最后,本书作者展示了如何用逼真的示例开发自定义标记库,读者可将其用作自己JSP库的出发点。 “这是一本很完整、很全面而且非常实用的书。作者出色地将他广博的经验与人共享,因此网页开发人员得以充分利用JavaServer Pages和相关网页技术。” ——Pierre Delisle,JSP标准标记库规范主管(JSP standard tag library specification lead) Hans Bergsten是Gefion Software的创始人,该公司致力于在J2EE技术的基础之上开发Java服务及产品。从servlet和JSP规范形成的时候开始,Hans始终是工作组中的积极参与者。他还为其他相关的JCP规范(诸如JSP Standard Tag Library,JSTL)做出了重要贡献,而且,作为Apache Jakarta项目管理委员会中的成员参与了用于servlet和JSP这两个规范的Apache Tomcat参考实现的开发
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值