Servlet中处理表单提交的数据

UseServlet.java

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/user.do")
public class UseServlet extends HttpServlet{

    private static final long serialVersionUID = 1L;
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //设置字符集格式为utf-8
        req.setCharacterEncoding("UTF-8");
        req.getRequestDispatcher("success.jsp").forward(req, resp);
        
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doPost(req, resp);
    }
}

index.jsp


    
用户名:
密码:
性别:
年龄:
Email:

success.jsp


    666,注册成功!
您的信息为:
用户名: <%=request.getParameter("name") %>
密码: <%=request.getParameter("pwd") %>
性别: <%=request.getParameter("sex") %>
年龄: <%=request.getParameter("age") %>
Email: <%=request.getParameter("email") %>
【回到主页】
Servlet中处理表单提交的数据_第1张图片
18.PNG
Servlet中处理表单提交的数据_第2张图片
19.PNG
20.PNG

你可能感兴趣的:(Servlet中处理表单提交的数据)