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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

web.xml finds servlet but JSP called by servlet cannot get back to the servlet

 
Ranch Hand
Posts: 338
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a servlet class that calls a JSP. The servlet loads okay and I see the JSP but when I hit the submit button on the JSP I get an error message.

The servlet is located at C:\tomcat\webapps\Reverse3Servlet\WEB-INF\classes\com\javaranch\drive\Reverse3Servlet.class

Here is my C:\tomcat\webapps\Reverse3Servlet\WEB-INF\web.xml file


The error message after I click on the jsp's submit button.


If I edit the web.xml changing the url-pattern (corrected example below).


then Tomcat can no longer load the servlet



This is the C:\tomcat\webapps\Reverse3Servlet\reverse3.jsp




 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<url-pattern></url-pattern>

You omitted the URL pattern.
 
margaret gillon
Ranch Hand
Posts: 338
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I screwed up the posting when I was cutting and pasting.
Once the web.xml has the pattern tomcat will not load it.




Tomcat reaction
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<url-pattern>/Reverse3Servlet</url-pattern>

am I right?
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags, not quote tags when posting code.

You made the url pattern "/com/javaranch/drive"? Why would you name it that? You should name it something that makes sense with respect to what the servlet does.

Some people use the servlet name, as Swastik posted, but I'm not a big fan of that. Using the word "servlet" anywhere in the URL reveals implementation details.
 
margaret gillon
Ranch Hand
Posts: 338
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<url-pattern>/Reverse3Servlet</url-pattern>



Tried that too and it did not work.




By the way each time I modify the web.xml I am completely stopping the tomcat server and shutting down the browser.
Tomcat is Version 7, java is jdk 1.6, behaviour occurs on Windows XP and Windows 7.
This is not run from a WAR file, I am moving the files into the tomcat\webapp directory manually and have verified there is no older version of a war for this project in tomcat.



 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

margaret gillon wrote:Tried that too and it did not work.


It sounds as if you do not understand what the URL pattern is for. You don't change it to "make things work", you set it to what you want the URL to get to the servlet to be. So it makes no sense to keep changing it. You set it, and change other things to match it.

Set it to something that makes sense, and then change the URL (in this case, the form action) to match it.

I can't tell anything about what Reverse3Servlet is supposed to do by its name (so it's probably not a good one), but let's run with it.

So let's make the URL mapping: <url-pattern>/reverse3</url-pattern>

Remember, you make this what you want it to be. Just make sure it's unique within the web app. This mapping is now the servlet path for the servlet.

Then, the action for your form would be:

Don't forget that the servlet path should be prefixed with the context path.
 
margaret gillon
Ranch Hand
Posts: 338
7
Tomcat Server Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I was misunderstanding the URL pattern and trying to use it as a directory mapping tool.



The pageContext is what I was missing in the reverse3.jsp

The form works now and the web.xml and reverse3.jsp are using the /reverse3 URL for the servlet.

Thank you, Bear.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
margaret gillon
Ranch Hand
Posts: 338
7
Tomcat Server Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For reference I am posting the final version of the two files.

The C:\tomcat\webapps\Reverse3Servlet\WEB-INF\web.xml file



This is the C:\tomcat\webapps\Reverse3Servlet\reverse3.jsp file.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic