Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run a servlet using Tomcat?

 
Gautam Sathe
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have compiled the servlet code. I used Java Web Server 2.0 which learning a little bit of servlet. I followed the following steps to execute the porgram:
1. Place the byte code(.class) file in the web server, eg d:\javawedserver2.0\servlets\HelloServlet.class
2. Run the web server ie execute d:\javawebserver2.0\bin\httpd.exe
3. Open the Web Browser and enter the URL "http://localhost:8080/servlet/HelloServlet"
Now how can I run the servlet using Jakarta Tomcat 4.0 Beta 6.
Thanks in advance.
Gautam.
------------------

[This message has been edited by Gautam Sathe (edited July 25, 2001).]
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After configuring tomcat, put your servlets(class file) in
webapps\WEB-INF\classes directory. Follow the template for the servlets already defined in web.xml to add a new one.
Restart the engine and check the servlet in the browser. http://localhost:8080/servlet/HelloWorldServlet
Regards
Beksy
 
Gautam Sathe
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Beksy,
Thanks for your help.
I could not get the directory webapps\WEB-INF\classes. I have jakarta-tomcat-4.0 Beta6 version of Tomcat. My server is starting up ok, but it shows file not found error when I save the file in this (C:\jakarta-tomcat-4.0-b6\webapps\examples\WEB-INF\classes) dirctory.
What do you mean by:
Follow the template for the servlets already defined in web.xml to add a new one.
Gautam.
Originally posted by Beksy Kurian:
After configuring tomcat, put your servlets(class file) in
webapps\WEB-INF\classes directory. Follow the template for the servlets already defined in web.xml to add a new one.
Restart the engine and check the servlet in the browser. http://localhost:8080/servlet/HelloWorldServlet
Regards
Beksy


------------------
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have placed the servlet classes in the examples (examples/WEB_INF/classes), your URL
will be http://localhost:8080/examples/servlet/HelloWorldServlet
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I missed the second question...
The following is from the tomcat docs
"* In order to define a name and init params for the newly installed
servlet you need to also:
register the servlet with a <servlet> element in the
WEBAPP/WEB-INF/web.xml file
you can optionally map your servlet
to uri requests relative to the context
within it is located by adding a <servlet-mapping>
element in the WEBAPP/WEB-INF/web.xml
file
"
 
Faisal Farooqui
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<b> I m also new in servlets, I got these Exceptions</b>

A Servlet Exception Has Occurred
Exception Report:
javax.servlet.ServletException: Cannot allocate servlet instance for path /examples/servlet/hello
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:406)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:219)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2251)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:984)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1074)
at java.lang.Thread.run(Thread.java:579)
Root Cause:
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class hello with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:50)
at java.lang.Class.newInstance0(Class.java:284)
at java.lang.Class.newInstance(Class.java:249)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:825)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:387)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:219)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2251)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:984)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1074)
at java.lang.Thread.run(Thread.java:579)
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Java one presentation on my web site.
www.samjdalton.com
I presented a Bids of a Feather session of web application deplyment which had a full discussion of this topic.
Please drop me a line if this is useful
Rgds
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic