Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

very very basic ques about using servlets

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
Sloan Bowman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic