Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question - servlet

Status
Not open for further replies.

shultz

Programmer
Oct 28, 2001
42
HK
Hi Guys,

This is my first post in the forum. I'm trying to work on servlets. I have a win98 system on which tomcat 4.0 has been installed. The JSP pages seems to work fine but when I try to execute the servlets, it gives me error like
"The requested resource (/test/servlet/HelloWorldExample) is not available."

I think I'm not configuring the server properly. Let me tell you what I have done.

My directory name is called test for which I have already made an entry in the SERVER.XML file under
"C:\Program Files\Apache Group\Tomcat 4.1\conf\"
as
<Context path=&quot;/test&quot; docBase=&quot;test&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; crossContext=&quot;true&quot;/>

uptil this point all the jsp files work fine. Now, for the servlets to work fine.. I created a WEB-INF directory under the test directory and a classes directory under the WEB-INF directory as:

&quot;C:\Program Files\Apache Group\Tomcat 4.1\webapps\test\WEB-INF\classes\&quot;

Then I created a basic web.xml file under web-inf directory like this:

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>

<!DOCTYPE web-app
PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
&quot;
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
</web-app>

and I wrote a HelloWorldExample.java program like this:

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

public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType(&quot;text/html&quot;);
PrintWriter out = response.getWriter();
out.println(&quot;<html>&quot;);
out.println(&quot;<body>&quot;);
out.println(&quot;<head>&quot;);
out.println(&quot;<title>Hello World!</title>&quot;);
out.println(&quot;</head>&quot;);
out.println(&quot;<body>&quot;);
out.println(&quot;<h1>Hello World!</h1>&quot;);
out.println(&quot;</body>&quot;);
out.println(&quot;</html>&quot;);
}
}

which compiles without any problem.

And then I execute the above servlet like this:

&quot;
for which I get the error as

*****

type Status report

message /test/servlet/HelloWorldExample

description The requested resource (/test/servlet/HelloWorldExample) is not available.

******

can anybody tell me what is the problem.. or how to make this program work..

thanks a ton in advance.
 
Chang your web.app to :
Code:
<web-app>
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  <servlet>
    <servlet-name>HelloWorldExample</servlet-name>
    <servlet-class>pack1.pack2.pack3.HelloWorldExample</servlet-class>
  </servlet>
</web-app>
Where pack1.pack2.pack3 is the packages path to reach your class. Water is not bad as long as it stays out human body ;-)
 
I changed the web.xml as follows
<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
<web-app>

<display-name>Tomcat Examples</display-name>
<description>
Tomcat Example servlets and JSP pages.
</description>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

</web-app>

but still it gives me the same problem. I don't have any packages for the HelloWorld.java

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

public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType(&quot;text/html&quot;);
PrintWriter out = response.getWriter();
out.println(&quot;<html>&quot;);
out.println(&quot;<body>&quot;);
out.println(&quot;<head>&quot;);
out.println(&quot;<title>Hello World!</title>&quot;);
out.println(&quot;</head>&quot;);
out.println(&quot;<body>&quot;);
out.println(&quot;<h1>Hello World!</h1>&quot;);
out.println(&quot;</body>&quot;);
out.println(&quot;</html>&quot;);
}
}

any other suggestions please?
 
My knowlege stops here. Try to ask your question in Tomcat forum, you'll get a better chance. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top