2013年9月13日星期五

the servlet request.getRequestDispatcher ("index.jsp") Jump to jsp page without any reaction

Purpose you want to jump to in the servlet jsp page.

index.jsp page in the root directory , there is no 404 errors .


	public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
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");

}

I
entered directly in the browser on the servlet address, and then print it out

dd
dd

explanation middle request.getRequestDispatcher ("/ index.jsp"). forward (request, response); must have executed , but nothing happens. I ask why ?
------ Solution ---------------------------------------- ----
request.getRequestDispatcher("/index.jsp").forward(request, response);


server-side adjustment , the address bar will not change.
------ Solution ---------------------------------------- ----
request.getRequestDispatcher () is a request forwarded front page sharing a request, so the url will not change.
response.sendRedirect () is re-directed , before and after the page is not a request, so this will change .
------ For reference only -------------------------------------- -
browser, enter the address after the transport servlet URL unchanged.
------ For reference only -------------------------------------- -
find the reason , it seems to jump when the URL does not change , that shows the servlet address
		String sql = "select * from Books where bno like ? or bname like ? or bkind like ?";
this.pstmt = this.conn.prepareStatement(sql);
pstmt.setString(1,"%"+keyWord+"%");
pstmt.setString(2,"%"+keyWord+"%");
pstmt.setString(3,"%"+keyWord+"%");

this sentence out of the question , the above is corrected , because the query is not found reason
------ For reference only ------------- --------------------------
saying landlord, I now have a problem is the servlet session where information is stored , and then jump to the jsp, jsp remove the session information and display , but my jsp pages have nothing, even the common words are not showing up , the problem is that the transition did not succeed because getRequestDispatcher or because of what ?
------ For reference only -------------------------------------- -

suggestions about the session in the console output data ( can be output in a servlet on the inside ) , see if it is null. every one statement output look, look for the wrong reasons ,
- ----- For reference only ---------------------------------------

recommendations about the session in the console output data ( can be output in a servlet on the inside ) , see if it is null. every one statement output look, look for the wrong reasons ,  

saying it directly in the servlet output, then the output is just an ordinary word , not output the contents of the database , using netbeans own database , built Entity Bean class will automatically generate code, so I really do not know where I wrong. With the success of the students still can not write the same . Logically speaking, there is no problem fishes , do I have a problem netbeans what ? = . =

------ For reference only ---------------------------------- -----
request.getRequestDispatcher () is forwarded , forwarded to another servlet or jsp go, you following System.out.println ("dd"); also perform ? This code is a problem .
request.getRequestDispatcher () back to add a return; otherwise error
Similarly , response.sendRedirect back also add a return;

------ For reference only ---------------------------------- -----
know Thank you

没有评论:

发表评论