转发
(1)什么是转发?
一个web组件(servlet/jsp)将未完成的处理转交
给另外一个web组件继续做。
比如,servlet将处理结果转发给jsp来展现。
(2)如何转发?
step1,绑订数据到request。
request.setAttribute(String name,Object obj)
注:
Object request.getAttribute(String name),
注意,该方法有可能返回null。
step2,获得转发器
RequestDispatcher rd =
request.getRequestDispatcher(String uri);
step3,转发
rd.forward(request,response);
(3)特点
1)转发之后浏览器地址栏的地址不变。
2) 转发的目的地必须是同一个应用。
3.处理servlet异常
(1)转发
将异常提示信息绑订到request,然后转发给
一个jsp来显示该异常提示信息。
(2)交给容器来处理
step1,将异常抛给容器
比如
throw new ServletException(e);
step2,配置异常处理页面
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/error2.jsp</location>
</error-page>