• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Newcommer To Servlets!

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i am a new commer to serlets. i created a simple servlet that displays a line of text. i placed in the webapps/root directory of tomcat. but when i use internet exlorer to see the address localhost:8080/HitServlet its says tje resource isnt ready yet. am using tomcat server 5.5 . what is the probrem. i placed a simple jsp with html in the same folder and the result was ok. the example servlets are also running ok. do i have to create a web app to use servlets. please help. thanks in anticipation.
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you create the servlet mapping in the web.xml?
 
mateen dar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did'nt do anything. i just complied the java file in placed in the webapps directory. i am studying core servlets and java server pages. i did exactly what it said. though it is using a older version of tomcat. could u tell me what i have to do . thanks.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mateen,

You require mapping entry in web.xml. From there actually tomcat will find ur source file and will generate class file. add follwing tag properly in web.xml by editing ur servlet-name and other entries...

<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>

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


HTH

bhavin
 
mateen dar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could u explain how and where to place the web.xml file. my servelt is based on a file called HitServlet.class . i place this in a directory class say FirstServlet that is in the webapps directory of tomcat. now do i place the hitservlet.class directly into the FirstServlet folder, and add the web.xmml u described before to this folder or what. thanks
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your web.xml should be in the WEB-INF directory inside your particular webapp dir. The classes should go in WEB-INF/classes with a proper directory structure conforming to the packages for the classes.
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you to read some tutorial first. That would be easier for you to start!

Try http://www.coreservlets.com
 
mateen dar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi this is the content of my web.xml file


<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>us.souther.simple.SimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>


</web-app>

the FirstServlet folder is in the webapps directory. and the claases are just as in the file.

now when i run http://localhost:8080/first i get an error . what am i
doing wrong. the directory structure is

/webapps/FirstServlet
/webapps/FirstServet/WEB_INF/classes
/webapps/FirstServet/WEB_INF/web.xml
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>us.souther.simple.SimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>


</web-app>


Here in the servlet class tag of servlet attribute give only as simpleservlet. The change is

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>SimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>


</web-app>
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mateen dar:
the FirstServlet folder is in the webapps directory. and the claases are just as in the file.

now when i run http://localhost:8080/first i get an error . what am i
doing wrong. the directory structure is

/webapps/FirstServlet



You should use the url http://localhost:8080/FirstServlet/first . Your FirstServlet is the webapp directory and it needs to be in the URL. If you would have placed the files in root, the URL would have worked.
 
mateen dar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. it worked. all that fuss about printing hello world. thanks alot.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic