日期:2014-05-20 浏览次数:20845 次
<html> <head> <title>测试doGet</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <form action="/doget_servlet" method="get"> <table><tr><td>输入名称后提交:<input type="text" name="name"> </td></tr> <tr><td><input type="submit" name="submit" value="确定"></td></tr> </table> </form> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <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 web-app_2_4.xsd" version="2.4"> <display-name>Welcome to Tomcat</display-name> <description> JSP </description> <servlet> <servlet-name>DoGetTestServlet</servlet-name> <servlet-class>classes.DoGetTestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DoGetTestServlet</servlet-name> <url-pattern>/doget_servlet</url-pattern> </servlet-mapping> </web-app>
public class DoGetTestServlet extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); PrintWriter out = response.getWriter(); out.println("获得了以下的参数: name=<br>" + request.getParameter("name")); out.flush(); } }