File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Http Error 500 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Http Error 500" Watch "Http Error 500" New topic
Author

Http Error 500

subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Hello,

I am using Tomcat 4.1. I just started working in it,
so this asking may be childish, if so, pls don�t
mistake me.

Here is my webapp structure:

1. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\classes
-----here i have my servlet classes
2. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\jsp
-----here i have a sample.htm file
3. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\WEB-INF
-----here is the web.xml resides

my web.xml entry is like this:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
</web-app>

------------------
the sample.htm has the following entries:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>
<p><font color="#000099">Hello, Welcome!</font> </p>
<form action="http:\\localhost:8080\testapp\TestServlet"
method="post" name="form1" target="_self">

<input type="submit" name="Submit" value="Click Me">
</form>

</body>
</html>

---------------

Here is what I done:
1. I started the Tomcat server
2. opened "http://localhost:8080/testapp/jsp/sample.htm"
3. clicked the button which gives the error "http 500 the TestServlet was not found"



Also please let me know in which folder should I put servlet,jsp and other files. Do I have to follow any structure/format?

Please tell me what is the problem?

Thank you!


Thank you,<br />Subi
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Servlets and all other classes MUST be in WEB-INF\classes .


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5

For best results put ALL classes in a package. Naturally the compiled class files must reside in directories under WEB-INF/classes that reflect the directory structure. See many discussions in this forum and the servlets forum about the use of packages.
Bill
subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Hello,

I have only one class in my classes directory:TestServlet.class. And it is a statndalone class no package defiend.

please tell now what should i do?

Thank you,
Subi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41601
    
  55

please tell now what should i do?


Read closely what William wrote :-)
The classes directory needs to be inside the WEB-INF directory.


Ping & DNS - my free Android networking tools app
subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Thnank you all.

Now it works after i have moved my classes directory into WEB-INF folder.
subi phoenix
Greenhorn

Joined: Jul 13, 2005
Posts: 15
Hello all,

I here posts the steps i carried out to execute the
servlet. If anyone have different idea pls post.

Steps to create your directory and work in Tomcat 4.1

1.Create your directory in Tomcat�s webapps
Directory.
�If your tomcat is in d:\ the your directory may look
�D:\tomcat\webapps\<your directory>
�E.g. �d:\tomcat\webapps\test�
2.In the test directory you can your html files
directly or you can create a directory to hold html
files.
�E.g. �d:\tomcat\webapps\test\first.html (OR)
�E.g. �d:\tomcat\webapps\test\html-files\first.html�
3.Create a folder called WEB-INF inside test
�E.g. �d:\tomcat\webapps\test\WEB-INF
�Under the WEB-INF folder put your web.xml file
4.Create another folder named classes under the same
test
�E.g. �d:\tomcat\webapps\test\classes
�Here you need to place your servlet classes
�E.g.
�d:\tomcat\webapps\test\classes\testServlet.class
5.Start any browser that are java enabled
6.Type �http://<machine name (or) IP add.
>:8080/<your folder name>/<html file>�
�E.g. http://localhost:8080/test/ html-files
/first.html
�E.g.
http://127.0.0.1:8080/test/html-files/first.html
7.Click the component (button, label�) to enable
servlet
8.That�s all! Now you should get your servlet
executed.

Files:

1.web.xml

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>testServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/testServlet/*</url-pattern>
</servlet-mapping>

</web-app>


2. first.html
<html>
<body>
<form method="POST"
action="http://localhost:8080/test/testServlet">
<input type=submit value=click></input>
</form>
</body>
</html>

3. testServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class testServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse res)throws ServletException,
IOException
{
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello! </h1>");
out.println("</body>"+"</html>");
}
}

I have put my first.html inside the folder
�d:\tomcat\webapps\test\html-files\� and testServlet
is under �d:\tomcat\webapps\test\WEB-INF\classes\� folder.
 
 
subject: Http Error 500