我正在使用 Eclipse IDE,下面的代码在浏览器上显示了空白屏幕。我不知道为什么它显示空白屏幕。有什么想法吗?提前致谢。
/**
* Servlet implementation class Ch1Servlet
*/
public class Ch1Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
Date dat=new Date();
System.out.println(dat);
out.println("<html>" + "<body>" + "<h1>Heello world</h1>" + dat + "</body>" + "</html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
请找到部署描述符文件。网页.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Monte</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Ch1Servlet</display-name>
<servlet-name>Ch1Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ch1Servlet</servlet-name>
<url-pattern>/Ch1Servlet</url-pattern>
</servlet-mapping>
</web-app>