aspose file tools*
The moose likes Servlets and the fly likes How to run a servlet using Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to run a servlet using Tomcat?" Watch "How to run a servlet using Tomcat?" New topic
Author

How to run a servlet using Tomcat?

Gautam Sathe
Greenhorn

Joined: May 24, 2001
Posts: 18
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

Joined: Jul 11, 2001
Posts: 254
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

Joined: May 24, 2001
Posts: 18
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

Joined: Jul 11, 2001
Posts: 254
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

Joined: Jul 11, 2001
Posts: 254
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

Joined: Jun 25, 2001
Posts: 13
<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)

====<BR>FAF
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
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

<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to run a servlet using Tomcat?