public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String name = req.getParameter("username");
String pass = req.getParameter("password");
String[] hobbys = req.getParameterValues("hobby");
System.out.println("*************************");
System.out.println(name);
System.out.println(pass);
System.out.println(Arrays.toString(hobbys));
System.out.println("*************************");
//通过请求转发
//req.getRequestDispatcher("/success.jsp").forward(req,resp);
req.getRequestDispatcher(req.getContextPath()+"/success.jsp").forward(req,resp);
}
}
web映射
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.kuang.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>