主题:关于servlet不能运行的问题
请问我有一个servlet程序,如果放在tomcat的webapps里面,在浏览器输入:
http://localhost:8080/hello/hello可以正常运行,但是我把程序放在d:\test目录里面,d:\test是虚拟目录来的,在d:\test放置一个test.html文件,在浏览器输入
http://localhost:8080/test/test.html可以正常显示test.html页面的信息.(这个说明虚拟目录设置上没有问题吧!)(/test映射d:\test),但是我把刚才的hello目录里面的程序复制到d:\test里面,在浏览器里面输入http://localhost:8080/test/hello/hello却不可以正常显示。
先说一说文件的结构:
class文件放在:d:\test\hello\web-inf/classes/Hello.class
web.xml文件放在:d:\test\hello\web.xml
下面是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>
<!-- General description of your web application -->
<display-name>Echo Servlet</display-name>
<description>
Echo Servlet
</description>
<!-- define servlets and mapping -->
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
==============================================
下面是Hello.java文件,也就是Hello.class文件的源代码:
===============================================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>");
out.println("This is my first Servlet");
out.println("</title></head><body>");
out.println("<h1>Hello,World!</h1>");
out.println("</body></html>");
}
}
===============================================
请大家帮我看一看是什么问题。谢谢....
http://localhost:8080/hello/hello可以正常运行,但是我把程序放在d:\test目录里面,d:\test是虚拟目录来的,在d:\test放置一个test.html文件,在浏览器输入
http://localhost:8080/test/test.html可以正常显示test.html页面的信息.(这个说明虚拟目录设置上没有问题吧!)(/test映射d:\test),但是我把刚才的hello目录里面的程序复制到d:\test里面,在浏览器里面输入http://localhost:8080/test/hello/hello却不可以正常显示。
先说一说文件的结构:
class文件放在:d:\test\hello\web-inf/classes/Hello.class
web.xml文件放在:d:\test\hello\web.xml
下面是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>
<!-- General description of your web application -->
<display-name>Echo Servlet</display-name>
<description>
Echo Servlet
</description>
<!-- define servlets and mapping -->
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
==============================================
下面是Hello.java文件,也就是Hello.class文件的源代码:
===============================================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>");
out.println("This is my first Servlet");
out.println("</title></head><body>");
out.println("<h1>Hello,World!</h1>");
out.println("</body></html>");
}
}
===============================================
请大家帮我看一看是什么问题。谢谢....