首页 > 编程语言 > 详细

How to forward from a Java servlet to a JSP

时间:2015-06-18 21:46:48      阅读:180      评论:0      收藏:0      [点我收藏+]

 

Here‘s a quick example that shows a complete method that I use in a Java servlet to forward to a JSP (JavaServer Page).

Just pass the method an HttpServletRequest, an HttpServletResponse, and a URL, and you‘re in business. Note that my JSP url string typically looks something like "/myPage.jsp".

private void forwardToPage(final HttpServletRequest request, 
                           final HttpServletResponse response,
                           String url) 
throws IOException, ServletException
{
  RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
  dispatcher.forward(request,response);
}

  

If you need to perform a redirect from a servlet to a JSP instead, I‘ve also written a short "How to redirect from a servlet to a JSP" tutorial.

I‘ll try to post information here on the difference between a forward and a redirect soon.

How to forward from a Java servlet to a JSP

原文:http://www.cnblogs.com/hephec/p/4586838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!