码迷,mamicode.com
首页 > 编程语言 > 详细

How to forward from a Java servlet to a JSP

时间:2015-06-18 21:49:23      阅读:137      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!