File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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 -
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the form, use action="/ShowParameters" instead of action="ShowParameters".
 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Netbeans IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Netbeans IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Zhang Jones
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic