This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes confused with forwarding request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "confused with forwarding request" Watch "confused with forwarding request" New topic
Author

confused with forwarding request

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I have a jsp which will be submitted in to a first servlet which forwards the request to a second servlet.

I tried this on my home and in my office it gives two different results.

in my office when i call req.getRequestURL() in my second servlet it will give me the http://localhost:8080/processparam where i obtained the request dispather as req.getRequestDispatcher("processparam") in my first servlet.but same code when i run in my home instead of this it displays http://localhost:8080/test the url which will be invoked when i submit the JSP page for my first servlet test why is this happening it is the same code. what could be the reason.

and one more thing in my web.xml i have this

<servlet>
<servlet-name>contextparam</servlet-name>
<servlet-class>com.scwcd.test</servlet-class>
</servlet>

<servlet>
<servlet-name>processparam</servlet-name>
<servlet-class>com.scwcd.testparam </servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>contextparam</servlet-name>
<url-pattern>/contextparam/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>processparam</servlet-name>
<url-pattern>/processparam/*</url-pattern>
</servlet-mapping>

in my test.java file i will get the requestdispatcher and forward the request. once i get this URL http://localhost:8080/test on browser after submitting the JSP file in my office when i change url to http://localhost:8080/test/1/2/3 it works fine but same thing in my home system it throws stack overflow exception if i comment requestdispatcher code it works fine

I am REALLY CONFUSED WITH THIS FROM 3 DAYS can any body help me in solving this issue
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

why is this happening it is the same code. what could be the reason.

Different container ? How did you set the web-app tag in your web.xml ?


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16


Here is your problem. You are getting a dispatcher using a path relative to the current request. Which means that "/contextparam/processparam" will be called, which goes back to your first servlet again. And this loops until the stack explodes. You should use a path relative to the context instead :
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Thanks for the reply.

yes it is displaying the URL as /contextparam/processparam on the console but it is working fine in my office system but not in my home system

How did you set the web-app tag in your web.xml ? i just copied a web.xml file from examples folder and put my code with in <web-app> tag nothing else i did.

Please let me know if i am missing any thing.

Thanks
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

what version of tomcat should we use for SCWCD 1.5 ? i checked SCWCD links in the forum and found free server tomcat 5.5 but is there any specific server version to be used.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

put my code with in <web-app> tag nothing else i did.

If you are using different containers at home and at work, this may give you different results. I think that you should first declare the web-app tag properly to avoid the confusion. Check this FAQ.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I tried putting the extra elements for <web-app ...> from the specified location now it is giving other exception. can any body give me a correct
web.xml code with web-app...> and doc type elements it will be very help full

Thanks
[ April 09, 2008: Message edited by: raja ram ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

can any body give me a correct web.xml code with web-app...> and doc type elements it will be very help full

You still haven't told us which container you are using.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi Christophe Verre,

Thank you so much for all the replys and help. i am using tomcat on the index page it displays Apache Tomcat/4.1.36-LE-jdk14 if i am not wrong it is tomcat 4.1 correct.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Tomcat 4.1 ? This is the SCWCD forum. Are you studying for SCWCD ? If so, you should be using at least Tomcat5.x.
Tomcat 4.x only supports Servlets 2.3 :

Are you using Tomact4.1 both at home and at work ?
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Yes I am studying for SCWCD 1.5 only,ok i'll dowload tomcat 5.5 from the SACWCD links .

Yes I am using tomcat 4.1 in both the places.

Thanks
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Thanks for the reply I have installed Tomcat 5.0.28 in both the places and all my problems are solved.

Thanks
 
 
subject: confused with forwarding request
 
Similar Threads
Request Dispatcher problem
tomcat4
doubt in forwarding
EL question
Welcome file