• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet action

 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • 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
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11943
211
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Andrew,

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

John
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11943
211
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • 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?
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • 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: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic