日期:2014-05-17  浏览次数:20869 次

servlet中request.getRequestDispatcher("index.jsp")跳转到jsp页面没有任何反应
目的想要在servlet中跳转到jsp页面上。

index.jsp页面在根目录上,没有出现404错误。


	public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletExceptionIOException {
String path = "/index.jsp";
List<Books> all = null;
try{
all = DaoFactory.getIBookDaoInstance().findAll(" ");
}catch(Exception e){
e.printStackTrace();
}finally{

}
System.out.println("dd");
request.setAttribute("books", all);
request.getRequestDispatcher("/index.jsp").forward(request, response);
System.out.println("dd");

}


我直接在浏览器上输入的 servlet 地址,然后打印出来

dd
dd

说明中间的request.getRequestDispatcher("/index.jsp").forward(request, response);一定有执行,但是却没有任何反应。请问是为什么?

------解决方案--------------------
request.getRequestDispatcher("/index.jsp").forward(request, response);


服务器端调整,地址栏不会变的。
------解决方案--------------------
request.getRequestDispatcher()是请求转发,前后页面共享一个request ,所以url不会变。
response.sendRedirect()是重新定向,前后页面不是一个request,所以这个会变化。