Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Request Dispatcher probs

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic