以下是java-ServletDemo01的代码
-----------------------------------------
package com.javaweb.ch10;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class ServletDemo01 extends HttpServlet
{
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out=response.getWriter();
out.println("This is my first Servlet Application");
}
}
-----------------------------------------
以下是web.xml的代码
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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">
<servlet>
<servlet-name>ServletDemo01</servlet-name>
<servlet-class>com.javaweb.ch10.ServletDemo01</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo01</servlet-name>
<url-pattern>/ServletDemo01</url-pattern>
</servlet-mapping>
</web-app>
-----------------------------------------
我配置完,打开tomcat服务器,打开浏览器输入
http://localhost:8080/Pri_01/ch10/ServletDemo01,结果报错说
The requested resource (/Pri_01/ch10/ServletDemo01) is not available.
这是为什么?看到网上说xml没配对,可是我和书上是一模一样的啊。为什么没对?
话说21天这本书,貌似错误挺多的。要么就是说的不详细。。。
servlet
------解决方案--------------------
访问地址:http://localhost:8080/Pri_01/ServletDemo01 试试