This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Dispatcher probs

 
Mahesh Pinnamaneni
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic