本人在Tomcat服务器的webapps下发布了第一个HelloWorldServlet小应用
代码如下:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println(“doGet”);
}
}
将编译好的class文件放在了:(原因是本人的程序中有包名):
配置文件在这个位置:
配置文件的内容是:
<web-app xmlns=”http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd”
version=”3.0″>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>HW</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HW</servlet-name>
<url-pattern>/abc</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
浏览器下输入的url:http://localhost:8080/test/abc
出现404错误,为什么呀,希望各位高手帮忙解决一下,谢谢了
代码如下:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println(“doGet”);
}
}
将编译好的class文件放在了:(原因是本人的程序中有包名):
配置文件在这个位置:
配置文件的内容是:
<web-app xmlns=”http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd”
version=”3.0″>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>HW</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HW</servlet-name>
<url-pattern>/abc</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
浏览器下输入的url:http://localhost:8080/test/abc
出现404错误,为什么呀,希望各位高手帮忙解决一下,谢谢了
解决方案
10
class 那里要写全路径限定名吧
80
找到你的.classpath文件,看下里面的output的路径是不是“webapp/WEB-INF/classes”;
还有,你的 <servlet-class>HelloWorldServlet</servlet-class>,请写全包名:com.bysxt.servlet.HelloWorldServlet
还有,你的 <servlet-class>HelloWorldServlet</servlet-class>,请写全包名:com.bysxt.servlet.HelloWorldServlet
10
正解