JSP内置对象

来源:互联网 发布:北美吐槽君 知乎 编辑:程序博客网 时间:2024/04/30 18:35


都是Servlet API接口的实例

application:

  1.与之联系的是ServletContext类

  2.在JSP中获得:

<%

       ServletContext application=this.getServletContext(); //this估计是name_jsp类

     %>

  3.在Servlet中: ServletContextapplication=getServletConfig().getServletContext();

  4.常用方法:

           String getServletInfo()

          ServletContext getContext(String uripath)//获取local URL的application context

session:

  代表一次会话。建立连接会话开始,关闭浏览器会话结束

  1.在Sevlet中获得: HttpSessionsession=request.getSession(true);

  2.常用方法:

        void setAttibute(String name,Object value);

        Object getAttibute(String)

        boolean isNew();

        long getAttributeTime();

        String getId()

request:

封装一次请求,获取客户端请求参数必须使用该对象。

1.常用方法:

  String  getParameter(String paraName) 

没有setParameter()!!!!//通过容器实现,用于客户端重定向

        getAttribute

   ObjectsetAttibute(String attrName,Object attrValue)              

//web容器内部流转,仅仅是处理阶段,服务端重定向

  响应的服务器通过此方法把对象拷到内存

           当重定向到另一个页面,服务器负责拷到那个页面对应的内存,request和session都可以访问这块内存。

 

session也一样,只是声明周期不同

                                                                                 

WEB组件以链接方式时,被连接的getParameter()获得请求参数

          转发方式  时,被转发的getAttribute()和转发源共享request参数

          表单和链接传递参数使用getParameter,只是从上个页面的url form中获得

          如果request涉及多个类,后面还有湖区参数就采用getAttrubute,结果输出后request就结束了

 

 


原创粉丝点击