• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet action

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on the hfjsp book, doing the beer app. I have the first iteration of the app where I select a color and hit the submit button.
My action=beer1.do, which is a servlet. However, instead of seeing the color I selected, I get a 404 error, and can't figure out why.
I've looked at this a couple times and can't figure it out... Can someone help?

Here's my web.xml snippet:


The path of the app prior to hitting the submit button is:
http://localhost:9999/hfjsp/chapters/ch3/beer1.html

Do I need to append the chapters/ch3 to the front of the action, beer1.do, or should it just replace the path accordingly?

Thanks,

John
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your servlet mapping must use the full path that you also use in your hyperlink starting from the web application root.

If you still have trouble getting it fixed, post your HTML code so I can see your hyperlink.
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sebastian,

Ok, where does the full path go? In the web.xml, the form? I've tried both, with leading slashes and omitting the leading slashes.

Here's the page with the action on it...


Next, here's the web.xml snippet:



Since I've tried mixing/matching the slashes, I don't remember at what state I left this in, except I was in a frustrated one...

If you see anything obvious or need anything else, please let me know..

John
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your web.xml snippet:

John Gregory wrote:Here's my web.xml snippet:


You have not closed of the servlet tag with a "</servlet>", and the same thing applies to your "</servlet-mapping>" tag. Is this an accident of copying your XML to JavaRanch, or is your real web.xml also missing the close tags?
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew,

It is a copy/paste error...it is in the original web.xml file.

John
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this

 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought that the Beer1 class was in the com.example.web package - have you changed the package name, or is my memory incorrect?
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

Your action should be either action="chapters/ch3/beer1.do" or action="/hfjsp/chapters/ch3/beer1.do".
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your application's context path is /hfjsp, then why are you using this


instead you should use this

This will also change the form action from ${pageContext.request.contextPath}/hfjsp/chapters/ch3/beer1.do to ${pageContext.request.contextPath}/chapters/ch3/beer1.do
Or you can use this in the web.xml (like you did in your original code)

and this in the JSP form action
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct. That's the package it's in. He has certainly changed that. May be there is a new version of the book that uses this package structure. Regardless, as long as it's mapped correctly, it should work.

Andrew Monkhouse wrote:I thought that the Beer1 class was in the com.example.web package - have you changed the package name, or is my memory incorrect?

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic