码迷,mamicode.com
首页 > Web开发 > 详细

Jsp2

时间:2017-03-23 02:44:41      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:bool   https   路径   定时   int   date   etc   let   属性   

一:JSP的概念
JSP(Java Server Page)Java服务页,是在HTML页面中嵌入Java程序,
运行于服务器端的动态网页技术。
JSP=HTML+Java
JSP与Servlet的关系是什么?
两者本质一样。

二:JSP中的Scriptlet代码
1.<%!
类、方法、常量、全局变量
%>

2.<%
Java语句,局部变量
%>

3.<%=变量或常量%>

三:JSP内置对象
1. request
String getParameter(String name) 通过参数名获取请求参数值
ServletContext getServletContext() 获取ServletContext对象
setAttribute(String name,Object o) 设置属性
removeAttribute(String name) 移除属性
Object getAttribute(String name) 获取属性
setCharacterEncoding(String charset) 设置请求编码

String[] getParameterValues(String name) 获取一组参数
HttpSession getSession() 获取会话对象session

Enumeration<String> getHeaderNames() 返回请求消息头名称
String getHeader(String name) 通过消息头名称获取消息头内容
Cookie[] getCookies() 返回cookie

2. response
setContentType(String type) 设置响应内容类型(MIME)
setCharacterEncoding(String charset) 设置响应编码
Collection<String> getHeaderNames() 返回响应消息头名称
String getHeader(String name) 返回响应消息头名称对应的消息内容
sendRedirect(String location) 客户端跳转
response.setHeader("refresh", "定时刷新的时间"); // 定时刷新
response.setHeader("refresh","定时跳转时间;URL=跳转路径"); // 定时跳转

addCookie(Cookie cookie)
注意:如何实例化Cookie?
Cookie c=new Cookie(String name, String value)

3.session(会话)------HttpSession接口的对象
setAttribute(String name,Object o) 设置属性
removeAttribute(String name) 移除属性
Object getAttribute(String name) 获取属性
void invalidate() 使当前会话失效
String getId() 返回当前session会话的ID
boolean isNew() 判断是否为新用户

Cookie保存于客户端,属于Header头信息之一。
其中有一个名为JSESSIONID的Cookie,此Cookie值保存的是会话ID。
Cookie c=new Cookie(String name, String value);
c.setPath("/"); // 设置Cookie的可见路径
c.setMaxAge(int expiry); // 设置Cookie的保存时间,以秒为单位;若为0,则删除此Cookie

4.application 代表容器(相当于ServletContext接口的对象)
setAttribute(String name,Object o) 设置属性
removeAttribute(String name) 移除属性
Object getAttribute(String name) 获取属性
String getRealPath(String path) 通过虚拟路径获取真实路径

5.pageContext (可以设置当前页的属性范围,甚至各种范围的属性)
setAttribute(String name,Object o) 设置属性
removeAttribute(String name) 移除属性
Object getAttribute(String name) 获取属性

setAttribute(String name,Object value,int scope)
removeAttribute(String name,int scope)
Object getAttribute(String name,int scope)




Jsp2

标签:bool   https   路径   定时   int   date   etc   let   属性   

原文地址:http://www.cnblogs.com/mingmng/p/6602665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!