• Post Reply Bookmark Topic Watch Topic
  • New Topic

registering a servlet

 
Jay Salman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading moreservlets and one of the exercises suggests that I add properties in the web.xml file. I did that but I the server does not recognize the ShowMsg as the servlet name. it's either I placed the file under the wrong directory, which I don't think so, or TOMCAT does not realize the location of the servlets.properties (where the servlet is registered) which is more likely. How do I know where tomcat is expecting to see that properties file so i can place it in the right directory.
Thanks mss101@hotmail.com
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>ShowMsg</servlet-name>
<servlet-class>moreservlets.ShowMessage</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>First Parameter Value</param-value>
</init-param>
</servlet>
</web-app>
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. In Java, names are CASE SENSITIVE, so the URL will be http://myserver/myapp/ShowMsg
2. In tomcat, normally you install the webapp into the tomcat webapps directly, either as an open directory tree or as a WAR. Tomcat will unpack WARs into directory trees. The Tomcat conf/server.xml file controls this behavior.
Your servlet class be in Tomcat's
webapps/myapp/classes/moreservlets/ShowMsg.class file or in a JAR in webapps/myapp/lib where the jar contains moreservlets/ShowMsg.class
There's a Tomcat forum for Tomcat-specific questions, BTW, though the directory structure for webapps is Sun J2EE standard and not just specific to Tomcat. The difference here is that other servers may require a WAR and not open directories, and either have a different place to install to than Tomcat's webapps directory and/or may install via a control-panel webapp.
 
Jay Salman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I do http://localhost:8080/servlet/moreservlets.ShowMessage
i get the page but without the init parameters. If I do http://localhost:8080/servlet/moreservlets.ShowMsgI get HTTP Status 404 page. According to the book, in servlet.properties, you register ShowMsg to refer to ShowMessage.class which I did, but it looks like server.xml does not see where I put that file or thinks its in the wrong directory. Any ideas?
yahoo ID majdalla
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!