index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--${pageContext.request.contextPath}获取当前项目路径,需要导入jsp servlet的依赖包--%>
public class Req extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
String name = req.getParameter("username");
String pwd = req.getParameter("password");
System.out.println(name+":"+pwd);
String[] hobbys = req.getParameterValues("hobbys");
System.out.println(Arrays.toString(hobbys));
req.getRequestDispatcher("login.jsp").forward(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
3.注册servlet



