JSP中5种对象总结

来源:互联网 发布:用python 编写操作系统 编辑:程序博客网 时间:2024/05/17 22:47

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资源很有限,一直存在服务器端,因此资源非常有限,应尽量少使用。

 

 
原创粉丝点击