我的Servlet出现问题。当我在Apache Tomcat中执行代码时,它返回以下消息:
type Informe de estado (status report)
mensaje /certificacion/ch1/Serv1
descripción El recurso requerido no está disponible. (Not available resource)
我的代码很简单。 xml包含:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app 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"
version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>
Servlet包含:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html> "+"<body>"+"<h1 align=center>Chapter1 Servlet</h1>"+"<br>"+today+"</body>"+"</html>");
}
}
文件夹结构为:
--tomcat
->webapps
->certificacion
->ch1
->WEB-INF
->web.xml
->classes
->Ch1Servlet.class
该示例摘自《 Head First Servlets&JPS》第31页。
你能帮助我吗?
最佳答案
如果应用程序部署在根上下文中,请尝试
主机:端口/ Serv1
否则这会工作
主机:端口/证书/ Serv1