Servlet复习



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映射



LoginServlet
com.kuang.servlet.LoginServlet


LoginServlet
/Login