java-ServletConfig-ServletContext-重定向、请求分派理解汇总 总结精华。
................ <init-param>
<param-name>charset</param-name>
<param-&#118alue>GB2312</param-&#118alue> </init-param> ................. </web-app>
注 意以上格式只是2.0以后的标准格式.旧容器(引擎)采用服务商自己的格式配置.注意它的父元素应该是<web-app>也就是说它是对一个 应用作用的.而如果只有一个特定的servlet要设定的参数.其它servlet不能共享.应该配置为ServletConfig参数.如一个读取附件 的servlet要用到绝对目录.而别的servlet不会用到: <servlet>
<servlet-name>GetAtt</servlet-name>
<servlet-class>mail.GetAttServlet</servlet-class> <init-param>
<param-name>absPath</param-name>
<param-value>/usr/mail/ax/axman/Maildir/</param-value> </init-param> </servlet>
不 用说.因为在<servlet>标签中已经指定了name和class,也就是说只有mail.GetAttServlet这个 servlet中才能取到path,而别的Servlet是不能取到的.那么如何访问这两个对象的参数呢?访问ServletConfig参数:
首 先要取得ServletConfig对象.然后调用它的getInitParameter();方法.要访问ServletConfig对象.jsp中直 接使用config内置对象.但因为你的JSP编译后的servlet一般不会被加到web.xml中的.所以一般不会通过jsp来取对本JSP编译后的 servlet的配置参数.那么在servlet中要得到ServletConfig对象有两种方法: 在inii()方法中取到:通过init的重载方法传递 .....
public class Test extends HttpServlet {
ServletConfig config;
public void init(ServletConfig config) throws ServletException { this.config = config; }
.................. }
然后在下面的方法中就可以访问config对象.但要注意.为了确保能从构造方法中到到当前servlet的
config对象.应该调用父类的构造方法: .....
public class Test extends HttpServlet {
ServletConfig config;
public void init(ServletConfig config) throws ServletException {
Servlet中的重定向和请求分派_理学_高等教育_教育专区。Servlet中的重定向和... JSP-Servlet转发与重定向... 2页 免费 java-ServletConfig-Ser... 22页 1...
java Servlet请求转发和重定向_工学_高等教育_教育专区。java Servlet请求转发和...();或或 ServletContext context = this.getServletConfig().getServletContext(...
深入理解ServletJSP之“转发和重定向”_IT认证_资格考试/认证_教育专区。深刻...浏览器收 到该重定向响应后会自动的向响应信息头中所指示的地址发出请求。整个...
ServletConfig与ServletContext对象详解_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 ServletConfig与ServletContext对象详解_计算机软件及...
05-Servletconfig&ServletCOntext_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 05-Servletconfig&ServletCOntext_计算机软件及应用_IT/...
servletconfig和servletcontext_IT/计算机_专业资料。servletconfig和servletcont...我个人认为:容器保存了很多个 ServletContext 对象,请求时容器 到底取哪一个\r ...
下面是HttpServletResponse.sendRedirect 方法实现的请求重定向与RequestDispatcher.forward 方法实现的请求转发的总结比较: (1)RequestDispatcher.forward 方法只能将请求...
java-ServletConfig-Servl... 22页 1财富值 Java重定向输出流实现程序... ... java Servlet请求转发和重... 3页 免费 ServletContext与ServletC... 3页 ...
它可以分派用户的请求并选择恰当的视图以用于显示,同时它也可以解释用户的输入并...Servlet容器卸载Servlet之前被调用,释放一些资源 8.servletContext与servletConfig...
请求重定向和请求分派 33 2008年9月24日 星期三 ...(getServletConfig().getInitParameter(“adminEmail...servlet和ServletContext初始化参数 ?作用域属性 ?...
热门文档