日期:2014-05-17 浏览次数:20831 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Welcome you!</title> </head> <body> <form action="welcome" method="get"> 请输入用户名:<input type="test" name="user" > <input type="submit" value="提交"> <form> </body> </html>
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Welcome extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String user=req.getParameter("user"); String welcomeInfo="Welcome you,"+user; resp.setContentType("test/html"); PrintWriter out=resp.getWriter(); out.println("<html><head><title>"); out.println("Welcome Page"); out.println("</title></head>"); out.println("<body>"); out.println(welcomeInfo); out.println("</body></html>"); out.close(); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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_2_5.xsd"> <servlet> <servlet-name>helloworld</servlet-name> <servlet-class>SimpleHello</servlet-class> </servlet> <servlet> <servlet-name>welcome</servlet-name> <servlet-class>Welcome</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloworld</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>welcome</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping> </web-app>