aspose file tools*
The moose likes Servlets and the fly likes Where I am going wrong in the example of JEE6 using @WebServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where I am going wrong in the example of JEE6 using @WebServlet" Watch "Where I am going wrong in the example of JEE6 using @WebServlet" New topic
Author

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

Kr. Pallav
Ranch Hand

Joined: Mar 06, 2010
Posts: 32

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 -


~|>@//@\/~
Kumar Pallav
-------------------
SCJP 5: 86 %, SCWCD: 91%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

In the form, use action="/ShowParameters" instead of action="ShowParameters".


[My Blog]
All roads lead to JavaRanch
Kr. Pallav
Ranch Hand

Joined: Mar 06, 2010
Posts: 32

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 06, 2010
Posts: 32

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

Joined: Mar 06, 2010
Posts: 32

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

Joined: Jan 10, 2002
Posts: 60055
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Feb 02, 2011
Posts: 16
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

Joined: Jan 10, 2002
Posts: 60055
    
  65

I already gave you the code. Just replace the hard-coded context path with the EL expression.
Zhang Jones
Greenhorn

Joined: Feb 02, 2011
Posts: 16
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

Joined: Jan 10, 2002
Posts: 60055
    
  65

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

Joined: Feb 02, 2011
Posts: 16
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

Joined: Jan 10, 2002
Posts: 60055
    
  65

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

Joined: Feb 02, 2011
Posts: 16
Thank you very much!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where I am going wrong in the example of JEE6 using @WebServlet
 
Similar Threads
calendar
calendar
Problem:The requested resource (/ShowParameters) is not available
About create a session!
send variable value from one servlet to another servlet for itext pdf