doPost
@WebServlet("/servlet2")//使用此注解,就不用在web.xml里配置Servlet了
public class Servlet2 extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置请求体的字符集位utf-8,从而解决post请求的中文乱码问题
req.setCharacterEncoding("utf-8");//解决post请求乱码
resp.setContentType("text/html;charset=UTF-8");
String username = req.getParameter("username");
System.out.println(username);
resp.getWriter().write("你好,我是尚硅谷");
}
}