The problem you are seeing has to do with the paths to the jsp and servlet. As long as 
you are using Servlet 2.2 or later, using a /path/servlet and /path/jsp have the same 
affect, they start in the "root" web dir of the web application being called. So, if 
you have folders www, www/jsp-pages, www/WEB-INF/ www/WEB-INF/classes and in the 
/classes dir is your servlet, the /servlet-name starts in the www/WEB-INF/classes 
root, where as the /jsp-page starts in the /www dir. To forward from a servlet to a 
JSP, you want to use the /path-to-jsp page. If you want to forward to another servlet, 
you would use the /package-name/servlet-name approach.

However, I love to "propose" the MVC approach, like Struts or my own mvc framework, 
theseus (www.theseus.org). It is quite a bit easier to have everything go through a 
single controller servlet, which dispatches to an appropriate action class. The 
response of the action is used by the framework to determine what jsp page to forward 
to. Very simple stuff actually. So, you can have your two buttons submit to the same 
on action class, each calling a different method. Both of which can forward back to 
the same one JSP page, all without ever using a redirect. Struts and my framework both 
use auto-population of javabeans as well, so that you don't have to call 
request.getParameter(), but instead can use a JavaBean "model" approach to the data 
passed around your pages, so that input values AND values to be displayed (output) can 
both be stored in a single javabean (or more if you like), to further make your code 
more maintainable and separated into component areas (MVC).


> -----Original Message-----
> From: Vikramjit Singh [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 07, 2002 2:11 AM
> To: [EMAIL PROTECTED]
> Subject: request dispatcher problem
> 
> 
> Hi,
> 
> i am having problem with RequestDispatcher. I have a jsp. 
> which has two
> buttons. On pressing button1 the form values are submitted to 
> the same jsp
> and the query is fired and the table is displayed which has 
> check boxes. Now
> the button2 appears, which submits the form values to a servlet. The
> checkboxes values are taken and entered into the database. 
> After the values
> are entered, the servlet sends the request object back to the 
> same jsp page
> by using RequestDispatcher interface. i need this because i 
> want to show the
> user that which check boxes he had checked are the ones 
> entered in database.
> 
> 
> When i right click the page, i get to see the servlet path like
> CONTEXTNAME/SERVLET/JSPNAME. ok fine didnt have any problem 
> with that. The
> problem comes when i press button1 to get other search 
> values, to post the
> form to the same jsp. It says page not found because it is 
> searching the jsp
> in the servlet directory. While if i press button2, the form 
> goes to the
> correct servlet.
> 
> I can use response.sendRedirect(), but dont wanna do that, 
> coz its much
> better and faster using a RequestDispatcher interface. Is 
> there any work
> around for this problem. Could some java gurus throw some light.
> 
> Thanks in advance,
> Vikramjit Singh.
> 
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body: 
> "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set 
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
> 
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com
> 

==========================================================================To 
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to