<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>My Web Application</display-name> <description> A application for test. </description> </web-app>
在myapp下用记事本新建一个测试的jsp页面,文件名为index.jsp,文件内容如下:
<html><body><center> Now time is: <%=new java.util.Date()%> </center></body></html>
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet (HttpServletRequest request ,HttpServletResponse response) throws ServletException,IOException {
response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>"); out.println("This is my first Servlet"); out.println("</title></head><body>"); out.println("<h1>Hello,World!</h1>"); out.println("</body></html>");