JSP五种页面跳转方式

 JSP五种页面跳转方式
1.<jsp:forward page="要跳转的页面" />(我测试了可以用的)
2.response.setHeader("Location","");(这个好像不可以哦,上网很多人说可以的。偶不晓得?)
3.response.sendRedirect("要跳转的页面");(我测试了可以用的)
4.request.getRequestDispatcher("/要跳转的页面").forward(request, response);(我测试了可以用的)
5.this.getServletContext().getRequestDispatcher("/要跳转的页面").forward(request, response);(我测试了可以用的)

 

另注:第二种用法response.setHeader("Location","");用法如下

(声明:这个部分摘自ttp://chxkyy.javaeye.com/blog/176239

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String   newLocn   =   "/newpath/jsa.jsp ";
response.setHeader( "Location ",newLocn);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章