aspose file tools*
The moose likes Servlets and the fly likes Newcommer To Servlets! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Newcommer To Servlets!" Watch "Newcommer To Servlets!" New topic
Author

Newcommer To Servlets!

mateen dar
Greenhorn

Joined: Dec 27, 2004
Posts: 26
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.
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Did you create the servlet mapping in the web.xml?


Cheers!<br /><b>Annie</b>
mateen dar
Greenhorn

Joined: Dec 27, 2004
Posts: 26
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.
Bhavin Sanghani
Ranch Hand

Joined: Dec 17, 2003
Posts: 67
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

Joined: Dec 27, 2004
Posts: 26
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

Joined: Mar 05, 2005
Posts: 172
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

Joined: Mar 05, 2005
Posts: 172
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

Joined: Dec 27, 2004
Posts: 26
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
kanchi panneer
Greenhorn

Joined: Mar 23, 2005
Posts: 3
<?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

Joined: Mar 05, 2005
Posts: 172
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

Joined: Dec 27, 2004
Posts: 26
thanks. it worked. all that fuss about printing hello world. thanks alot.
 
Don't get me started about those stupid light bulbs.
 
subject: Newcommer To Servlets!