Servlet部署的问题?
Class文件为:
package com.servlet;
import
java.io.IOException;
import java.io.PrintWriter;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class MyServlet extends HttpServlet {
//继承父类构造方法
public MyServlet(){
super();
}
//重写父类的DOGET方法
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,
IOException{
doPost(request,response);
}
//重写父类的DOPOST方法
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
PrintWriter out=response.getWriter();
out.println("你好,你就是一个SB!FUCK YOU!");
out.flush();
out.close();
}
}
web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.servlet.MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<display-name>第一个Servlet</display-name>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/myFirstServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
当在浏览器输入:http://localhost:8080/servletDemo/myFirstServlet
提示这样的错误:
type Status report
message /servletDemo/myFirstServlet
description The requested resource (/servletDemo/myFirstServlet) is not available.
如果是:http://localhost:8080/servletDemo的话,打开index.jsp
这个没的问题的,能正常显示。就是调用MyServelt映射地址就出错了。。WHY?谢谢。。
------解决方案--------------------检查MyServlet.class存放位置:WEB-INF/classes/com/servlet/MyServlet.class
------解决方案--------------------在 Eclipse的“包资源管理器(Package Explorer)”检查文件存放的位置。由于META-INF
WEB-INF文件夹下的内容无法对外发布,所以,如果你引用了带这两个目录的文件,肯定是不允许。例如: http://localhost:8080/guestbook/WEB-INF/index.html就是错误的
文件位置存放错误。
------解决方案--------------------
servlet-name写成invoker试试
<!--request like this "http://localhost:8080/dwrtest/servlet/com.test.dwr.DWRServlet" -->
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>