现在的位置: 首页 > 综合 > 正文

JSP中5种对象总结

2018年04月17日 ⁄ 综合 ⁄ 共 868字 ⁄ 字号 评论关闭

2008-0410

Request

Request
分服务器跳转和客户端跳转。

服务器跳转:在request对象中的Attribute在一个不间断的请求中一直保存。跳转时页面的地址不改变。注意AttributeParamater的区别。

(jsp): <jsp:forward  page=url
/>

                        (servlet): req.getRequestDispatcher(String url).forward(req, resp);

客户端跳转:只能在当前页面存在。跳转时页面地址改变。

response.sendRedirect(url);

重要的方法:

                        getParamater(String name);

                        setAttribute(String name, String value);

                        getAttribute(String name);

                        setCharacterEncodeing(String charsetName);

 

Response

Response主要作用是给客户端做出响应。有几个常用的用法:           

                        setHeader(String name, String value): 
常用作设置客户端的自动跳转,
设置页面失效时间等等。

                        sendRedirect(String url):
客户端跳转。

 

Page:设置的Attribute只在当前页面有效。

 

Session:设置的Attribute在当前session有效,
即只要浏览器不退去,
session就有效。

 

Application:设置的Attribute
只要不重启服务器,
就一直有效。Application资源很有限,
一直存在服务器端,因此资源非常有限,
应尽量少使用。

 

 

抱歉!评论已关闭.