ServletConfig
来源:互联网 发布:南风知我意 琰阙全文 编辑:程序博客网 时间:2024/04/29 19:15
ServletConfig对象
• 在Servlet的配置文件中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数。
• 当servlet配置了初始化参数后,web容器在创建servlet实例对象时,会自动将这些初始化参数封装到ServletConfig对象中,并在调用servlet的init方法时,将ServletConfig对象传递给servlet。进而,程序员通过ServletConfig对象就可以得到当前servlet的初始化参数信息。
• 阅读ServletConfig API,并举例说明该对象的作用:
– 获得字符集编码
– 获得数据库连接信息
– 获得配置文件
• WEB容器在启动时,它会为每个WEB应用程序都创建一个对应的ServletContext对象,它代表当前web应用。
• ServletConfig对象中维护了ServletContext对象的引用,开发人员在编写servlet时,可以通过ServletConfig.getServletContext方法获得ServletContext对象。
也可以使用 this.getServletContext方法
• 由于一个WEB应用中的所有Servlet共享同一个ServletContext对象,因此Servlet对象之间可以通过ServletContext对象来实现通讯。多个Servlet通过ServletContext对象实现数据共享。
• ServletContext对象通常也被称之为context域对象。(request,session,page)
setAttribute(),getAttribute();
ServletContext应用
• 获取WEB应用的初始化参数。
<context-param>
<param-name> data</param-name>
<param-value> xxxx</param-value>
</context-param>
• 实现Servlet的转发。
RequestDispatcher rd =getServletContext().getRequestDispatcher(“/1.jsp”);
rd.forward(request,response);
如何把数据传到 1.jsp ?(可以通过request域,不能用context域)
• 利用ServletContext对象读取资源文件。
– 得到文件路径
– 读取资源文件的三种方式
– .properties文件(属性文件)
• ServletConfig和ServletContext的区别
– 整个Web应用只有一个ServletContext,在部署Web应用的时候,容器会建立这一个ServletContext对象,这个上下文对Web应用中的每个Servlet和JSP都可用。
– Web应用中的各个Servlet都有自己的ServletConfig,它只对当前Servlet有效。
- ServletConfig
- servletConfig
- ServletConfig
- servletconfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig
- servletConfig
- servletconfig
- ServletConfig
- ServletConfig
- ServletConfig
- ServletConfig原理
- ServletConfig接口
- ServletConfig接口
- ios处理判断手机号码的正则表达式,基本上包含全部的手机号段
- 英文投稿的一点经验
- 复制来的幸福,始终粘贴不到自己身上:伤感日志
- 1个可以旋转html元素的jquery插件
- Android之shape与selector实现圆角
- ServletConfig
- document.getElementById为空或不是对象的解决方法
- Huffman编码
- WebScarab关键源码分析(5)
- C#笔记01:helloworld!
- listview底部加载更多的操作
- IOS开发---绘制饼图
- 配置Tom-cat使用帮助
- Ubuntu 12.04下安装Google Chrome 21稳定版