aspose file tools*
The moose likes Servlets and the fly likes Request Dispatcher probs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatcher probs" Watch "Request Dispatcher probs" New topic
Author

Request Dispatcher probs

Mahesh Pinnamaneni
Ranch Hand

Joined: Jul 02, 2004
Posts: 100
hai guys,

i am trying to execute the RequestDispatcher problem but it is giving me an error 404 "the page /project/admin.jsp" can't found.but its there in the dir.
here it goes.in my dir of webapps (tomcat 5.0) /project/ there are admin.jsp,dataentry.jsp,manager.jsp etc.
when i press the submit button of login.html page it will call Servlet for which the code is shown below:
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
String accounttype = request.getParameter("type");
String usr = request.getParameter("user");
String pwd = request.getParameter("password");
if(type.equals("Admin"))
gotoPage("/project/admin.jsp",request, response);
// project/admin.jsp project is the dir in my webapps folder of tomcat 5.0
// and admin.jsp is the page which is having req.getparameter();
else if(type.equals("Dept_User"))
gotoPage("/project/deptuser.jsp",request, response);
else if(type.equals("DataEntry"))
gotoPage("/project/dataentry.jsp",request, response);
else if(type.equals("Manager"))
gotoPage("/project/manager.jsp",request, response); }

private void gotoPage(String address,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher =getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response); } }//end of class

i also tried with res.sendRedirect(url), it is working.
plz tell me why i am getting this error . also the steps for using RequestDispatcher. plz mail me to itsmaheshp@yahoo.com is u have code for that.

thanks alot

regards,
Mahesh
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
Declare your jsps in your web.xml file like so:


Then use the following method to forward to the page


Doing it this way maps pages to logical names. If several pages contain links to the same page, and the page name changes or it is moved to a different location, you only need to change the mapping in the xml file instead of changing the link in every page.
[ August 13, 2004: Message edited by: Anthony Watson ]

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Request Dispatcher probs