• 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
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

very very basic ques about using servlets

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic