Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2003, 02:45 AM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why can't run servlet?

I have a servlet file,like follows:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class a1 extends HttpServlet{
    public void doGet(HttpServletResponse req,HttpServletResponse resp) throws ServletException,IOException{
        PrintWriter pw=resp.getWriter();
        pw.println("<html><body>Hello World!</body></html>");
        pw.close();
    }
}

and web.xml is follows:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!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>a1</servlet-name>
   <servlet-class>a1</servlet-class>
   </servlet>
</web-app>

I use Tomcat5.0,and I put a1.class into \Tomcat 5.0\webapps\test\WEB-INF\classes,and I have add a sentence into server.xml like follows:

<Context path="test" docBase="test" debug="0"/>

but when I run it in IE6,like follows:
http://localhost:8080/test/servlets/a1

it raises HTTP Status 404 error,"The requested resource (/test/servlets/a1) is not available."

Why? I have configure it! Please help.
Thanks in advance
Edward
 
Old September 26th, 2003, 01:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In server8080.xml you must form your application:
<?xml version="1.0" encoding="UTF-8"?>
<Server debug="0" port="8081" shutdown="SHUTDOWN">
  <Service name="Tomcat-Standalone">
    <Connector acceptCount="10" className="org.apache.catalina.connector.http.Http Connector" connectionTimeout="60000" debug="0" maxProcessors="75" minProcessors="5" port="8080"/>
    <Engine debug="0" defaultHost="localhost" name="Standalone">
      <Host appBase="C:\PROYECTS\myProyect\app\Tomcat\webapps" debug="0" name="localhost" unpackWARs="true">
        <Context debug="0" docBase="C:\PROYECTS\myProyect\app" path="/myContext" reloadable="true" workDir="C:\PROYECTS\myProyect\app\Tomcat\work\myC ontext"/>
      </Host>
    </Engine>
  </Service>
</Server>

Soon in the call you put:
htpp://localhost:8080/myContext/a1
 
Old November 9th, 2003, 12:02 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

change <Context path="test" docBase="test" debug="0"/>

to

<Context path="/test" docBase="test" debug="0"/>
restart tomcat
then run http://localhost:8080/test/servlets/a1

it will be ok.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regards Servlet file run in server sureshsdckap Apache Tomcat 1 July 13th, 2007 03:34 PM
Can JSP integrate with Servlet and run on MySQL wesleygch JSP Basics 0 April 10th, 2007 02:22 AM
how to run servlet? suchi Pro JSP 1 July 1st, 2006 07:36 PM
How to run servlet under application? kuterka Servlets 1 February 11th, 2005 08:21 AM
Run Servlet, Set Directory, Help ? Gika JSP Basics 3 April 2nd, 2004 06:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.