problem while running servlet

  • Thread starter Kaspar Minosiants
  • Start date
K

Kaspar Minosiants

Hello !
I've installed servlet programming environment recently

Tomcat 1.4
eclipse

I'm trying to run a simple servlet and can't to do it
I've tryed to put class file of this servlet into webapps/ROOT/
and run it _http://localhost:8080/servlet/Hello
in both cases 404 error appers
In the same time jsp pages without servlets work fine
What's a problem


code:
---------------------------------------------------------------
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.ServerException;
import javax.servlet.http.HttpServlet;import
javax.servlet.http.HttpServletRequest;import
javax.servlet.http.HttpServletResponse;public class Hello extends
HttpServlet{ public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServerException
PrintWriter out = response.getWriter(); String docType = "<!DOCTYPE
HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n";
out.println(docType + "<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" + "</BODY></HTML>"); } public void
doPost(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServerException
{ doGet(request,response); } }----------------------------------------
-----------------------------------Thanks
 
M

Manish Hatwalne

You need to put your servlet classes under -
webapps/ROOT/WEB-INF/classes
JSPs should be outside WEB-INF.

- Manish
 
K

Kaspar Minosiants

Thanks for the reply Manish

It's under classes dir
exactly in webapps/ROOT/WEB-INF/classes dir
I've tried to to put it in webapps webapps/examples/WEB-INF/classes dir
and it works
very strange :(
 
I

IP Freely

Kaspar Minosiants said:
Thanks for the reply Manish

It's under classes dir
exactly in webapps/ROOT/WEB-INF/classes dir
I've tried to to put it in webapps webapps/examples/WEB-INF/classes dir
and it works
very strange :(
Not Really.

You will need a servlet mapping in your webapps/ROOT/WEB-INF/web.xml file.
The examples context already has this mapping for its supplied hello world
example.
 
W

William Brogden

Kaspar Minosiants said:
Hello !
I've installed servlet programming environment recently

Tomcat 1.4
eclipse

I'm trying to run a simple servlet and can't to do it
I've tryed to put class file of this servlet into webapps/ROOT/
and run it _http://localhost:8080/servlet/Hello

The syntax of addressing a Hello servlet class as "/servlet/Hello"
requires the "invoker" servlet - it used to be on by default but
in Tomcat 4 it is off by default. Search your ../conf/web.xml
file for "invoker" to see the documentation.
 
W

William Brogden

Kaspar Minosiants said:
Thanks for the reply Manish

It's under classes dir
exactly in webapps/ROOT/WEB-INF/classes dir
I've tried to to put it in webapps webapps/examples/WEB-INF/classes dir
and it works
very strange :(

Simple - the web.xml in the /examples directory has the invoker servlet
turned on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top