1 package com.zdsofe.servlet1;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Enumeration;
6 import java.util.List;
7
8 import javax.servlet.ServletException;
9 import javax.servlet.annotation.WebServlet;
10 import javax.servlet.http.HttpServlet;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.http.HttpSession;
14
15 /**
16 * Servlet implementation class loginSrevlet
17 */
18 @WebServlet("/loginSrevlet")
19 public class loginSrevlet extends HttpServlet {
20 private static final long serialVersionUID = 1L;
21
22 /**
23 * @see HttpServlet#HttpServlet()
24 */
25 public loginSrevlet() {
26 super();
27 // TODO Auto-generated constructor stub
28 }
29
30 /**
31 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
32 */
33 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34 // TODO Auto-generated method stub
35 }
36
37 /**
38 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
39 */
40 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
41 //编码格式
42 request.setCharacterEncoding("utf-8");
43 response.setCharacterEncoding("utf-8");
44 response.setContentType("text/heml charset=utf-8");
45
46 //得到表单的数据
47 Enumeration<String > name=request.getParameterNames();
48 List<String> list=new ArrayList<String>();
49 while(name.hasMoreElements())
50 {
51 list.add(request.getParameter(name.nextElement()));
52 }
53
54 //创建Session对象
55 HttpSession ss= request.getSession();
56 ss.setAttribute("uName", list.get(0));
57 response.sendRedirect("/webProject1/jsp/loginWelcome.jsp");
58
59 }
60
61 }