aspose file tools*
The moose likes Servlets and the fly likes very very basic ques about using servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "very very basic ques about using servlets" Watch "very very basic ques about using servlets" New topic
Author

very very basic ques about using servlets

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Hi
I am done some programming in jsp and now started trying my hand in servlets. But i am unable to make my servlets run.
I am using tomcat 4.0.6 as server.
I have a JSP page which specifies name of a servlet in its action.
<form name="shoppingForm"
action="/servlet/ShoppingServlet"
method="POST">
Then in the WEB-INF/classes/servlet directory i have made a servlet called ShoppingServlet.
These are my entries in web.xml
<servlet>
<servlet-name>ShoppingServlet</servlet-name>
<servlet-class>servlet.ShoppingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShoppingServlet</servlet-name>
<url-pattern>/servlet/servlet.ShoppingServlet</url-pattern>
</servlet-mapping>

But when i submit the form i get the error: page does not exist
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
<servlet-mapping>
<servlet-name>ShoppingServlet</servlet-name>
<url-pattern>/servlet/servlet.ShoppingServlet</url-pattern>
</servlet-mapping>

here you have specified the url pattern "/servlet/servlet.ShoppingServlet" and you are accessing servlet using "/servlet/ShoppingServlet"
Change your entry in web.xml of url-pattern. change it to following
<servlet-mapping>
<servlet-name>ShoppingServlet</servlet-name>
<url-pattern>/servlet/ShoppingServlet</url-pattern>
</servlet-mapping>
Now try it will run.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
No no no - don't use /servlet/ - this gets you mixed up in the dreaded "invoker" servlet syntax - the cause of about 75% of all new programmer confusion.
See this ranch FAQ on the invoker servlet.
Also many many discussions on this and the Tomcat forum in recent weeks.
Bill
Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Thanks a lot
Sloan Bowman
Ranch Hand

Joined: Jan 21, 2003
Posts: 107
Simply put lets suppose you coded a servlet named AddToCart and it was located in the app package. Below would be how you would set it up on your web.xml

You would access your servlet by typing http://yourdomain.com/AddToCart
Let me know if you need any additional help.
 
 
subject: very very basic ques about using servlets