• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Http Error 500

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets and all other classes MUST be in WEB-INF\classes .
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


please tell now what should i do?



Read closely what William wrote :-)
The classes directory needs to be inside the WEB-INF directory.
 
subi phoenix
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnank you all.

Now it works after i have moved my classes directory into WEB-INF folder.
 
subi phoenix
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic