Servlet获取参数

 1 package action;
 2 
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.http.HttpServlet;
 8 import javax.servlet.http.HttpServletRequest;
 9 import javax.servlet.http.HttpServletResponse;
10 
11 public class LoginServlet extends HttpServlet {
12 
13     private static final long serialVersionUID = -7122725590964537174L;
14 
15     public LoginServlet() {
16         super();
17     }
18 
19     public void destroy() {
20         super.destroy();
21 
22     }
23 
24     public void doGet(HttpServletRequest request, HttpServletResponse response)
25             throws ServletException, IOException {
26         // request.getAttribute("name");// 获取属性
27 
28         String name = request.getParameter("name");// 获取参数
29         String pass = request.getParameter("pass");// 获取参数
30         response.setContentType("text/html");
31         PrintWriter out = response.getWriter();
32         out.println(name);
33         out.println(pass);
34 
35         out.flush();
36         out.close();
37     }
38 
39     public void doPost(HttpServletRequest request, HttpServletResponse response)
40             throws ServletException, IOException {
41 
42         response.setContentType("text/html");
43         PrintWriter out = response.getWriter();
44 
45         out.flush();
46         out.close();
47     }
48 
49     public void init() throws ServletException {
50         // Put your code here
51     }
52 
53 }

 

posted @ 2015-03-22 23:38  鲸歌  阅读(256)  评论(0编辑  收藏  举报