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

Where I am going wrong in the example of JEE6 using @WebServlet

 
Ranch Hand
Posts: 32
Netbeans IDE Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the JSP and Sevlet I am using while learning JEE6 through a new book (blackbook) I modified the code but I am not able to see the next page on submit of form and unable to find mistake.. I don't wish to use web.xml rather I want @WebServlet defined in class and work out the example ..
JSP

Servlet


Using Netbeans / Glassfish 3.1
Error -HTTP Status 404 -
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the form, use action="/ShowParameters" instead of action="ShowParameters".
 
Kr. Pallav
Ranch Hand
Posts: 32
Netbeans IDE Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply Marshal Christophe Verré but that didn't work and if we do that it even goes out of project scope only and after hitting action tab it goes like (http://localhost:8080/ShowParameters).. Any more suggestions
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the name of your application ? Change action="/ShowParameters" with "action="/nameofyourapplication/ShowParameters". There's a smarter way to do it, but let's just check if it works for now.
 
Kr. Pallav
Ranch Hand
Posts: 32
Netbeans IDE Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup Mashal I already tried those tricks but in vein .. anyway I really appreciate you for your time and patience ,I am trying here lets see if I get the solution I will post too... my app name is JEE6 I tried putting "/JEE6/ShowParameters"
 
Kr. Pallav
Ranch Hand
Posts: 32
Netbeans IDE Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry , I declared package structure wrongly .... while making package in "Source packages" in netbeans foolishly I made inside "Test Packages" it's working now with same above code .. Thanks for help and really sorry for putting such poor efforts and mistakes

 
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
By the way, you should not be hard-coding the context path into the URL. Use ${pageContext.request.contextPath} to fetch it dynamically.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:By the way, you should not be hard-coding the context path into the URL. Use ${pageContext.request.contextPath} to fetch it dynamically.



Thanks Bear. That's the "smarter way" I was referring to in my previous post.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:By the way, you should not be hard-coding the context path into the URL. Use ${pageContext.request.contextPath} to fetch it dynamically.

,but i failed as you said ,can you give me an example. thanks!
 
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
I already gave you the code. Just replace the hard-coded context path with the EL expression.
 
Zhang Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I already gave you the code. Just replace the hard-coded context path with the EL expression.

sorry,I don't know what is hard-coded,can you say more details?Thanks!!
 
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
The canonical format of an action attribute that addresses a servlet would be:

So if the context path were mywebapp and the servlet path were myservlet, the action would be:

However, it's a really poor practice to hard-code the context path in this manner because the context path is assigned by server configuration, not code. Rather, you should pick up the context path programmatically so that it will be correct no matter how the server is configured. So:

is the correct way to specify the action attribute to address the servlet.
 
Zhang Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The canonical format of an action attribute that addresses a servlet would be:

So if the context path were mywebapp and the servlet path were myservlet, the action would be:

However, it's a really poor practice to hard-code the context path in this manner because the context path is assigned by server configuration, not code. Rather, you should pick up the context path programmatically so that it will be correct no matter how the server is configured. So:

is the correct way to specify the action attribute to address the servlet.


Does context-path means project name and serlvet-path means servlet name?I feel very confused with these two terms!
 
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
Those are the proper names for those terms. You should be familiar with them.

If you are working with servlets, you should have read the Servlet Specification and have it handy.
 
Zhang Jones
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic