• Post Reply Bookmark Topic Watch Topic
  • New Topic

question related to servlet class and how to run it from Root  RSS feed

 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends i am new to servlet technology
i have installed Apache Tomcat 4.1
i want to run servlet servlet class file from Webapps/ROOT
i have stored my class file name HelloServlet.class in webapps\ROOT\WEB-INF\classes
initially in WEB-INF no classes folder exist i have created one

but when i try to run it from browser by giving path http://localhost:8080/servlet/HelloServlet

server gives 404 error

due to this problem
later on i have stored my class file in
webapps\examples\WEB-INF\classes
now server find out it and gives me proper results

i think the problem is due to my server.xml file Tomcat 4.1\conf\server.xml

in that due to following code i face problem

<!-- Tomcat Root Context -->
<!--
<Context path="" docBase="ROOT" debug="0"/>

-->
<!-- Tomcat Examples Context -->

<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.EmployeeRecordHome"
remote="com.wombat.empl.EmployeeRecord"/>


i tries to remove cooment part of Root context
and tries to put example context in comment part

<!-- Tomcat Root Context -->
<Context path="" docBase="ROOT" debug="0"/>


<!-- Tomcat Examples Context -->
<--
<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_examples_log." suffix=".txt"
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.EmployeeRecordHome"
remote="com.wombat.empl.EmployeeRecord"/>
-->



and save it
but after this i have major problem my server is refusing to start

friends would you please help me out in this condition and give solution how to run servlet from ROOT
Thanks in advance
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ganesh,

The problem must be with the mapping in your web.xml file .

Did u perform the servlet mapping (in web.xml):
ex
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.servlet.SampleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>

In the above case you can invoke this servlet(assuming that u have it inside ROOT ) as
http://localhost:8080/servlet

Hope this helps

Balaji
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks my dear friend Bajji

i have tried little differently

in web.xml of my ROOT App

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/jayesh</url-pattern>
</servlet-mapping>

i have done this particular thing

but can any one explain me importance of that server.xml file from config
or give me link related to it
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't recommend working from the ROOT directory.
Create your own application folder under webapps and add the WEB-INF dircectory.

If you'd like some examples, go to http://simple.souther.us.
And.. as Bajji mentioned, you will need to map your servlets in a web.xml file.
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ben
i am just new to sevlet technology

i have tried to create my seperate web app yesterday in my Webapps directory but it creates so many problems for me and i don't know so much about these *.xml files can any one provide link for it
and importance of that server.xml file because i think knowledge of this file is necessary
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server.xml file is just Tomcat's configuration file. It's not a part of the servlet spec. Other containers may use something different.

Understanding web.xml is very important. That is the main configuration file for a web app and is driven by the servlet spec. This file should be the same for any spec compliant servlet container.

There are links in my signature that (IMHO) belong in the personal toolbar of every java web developer's browser. The specs (which are PDFs) should live on your desktop.

You can also see the proper layout of a webapp (including a configured web.xm file) by downloading and running any of the example apps from the link that I gave you.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your use of /servlet/ in the URL indicates you may have gotten tangled up in the "invoker" servlet conventions. Read this ranch FAQ on the invoker.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!