Servlet jump problem in JAVA WEB!

problem description

I set four properties in Servlet! [image description] (and one is error message attribute) [1] need to be sent to the previous page for display and use. The transmission path is not a problem, because one of the four attributes is available, the username attribute is available at the front end, but the other three attributes are not available at the front end!

the environmental background of the problems and what methods you have tried

I try to output attributes in the Tomcat backend, all of which are available

related code (the following is the verification code of my Servlet)

/ / Please paste the code text below (do not replace the code with pictures)

public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String path = "test.jsp";
    String username = req.getParameter("username");
    String userpassword = req.getParameter("userpassword");
    List<String> err = new ArrayList<String>();
    if(username == null || "".equals(username)){
        err.add("");
        req.setAttribute("status","false");
    }
    if(userpassword == null || "".equals(userpassword)){
        err.add("");
        req.setAttribute("status","false");
    }
    if(err.size()==0){
        User user = new User();
        user.setUsername(username);
        user.setUserpassword(userpassword);
        try {
            if(!DAOFactory.getIUserDAOInstance().findVerification(user)){
                err.add("");
                req.setAttribute("status","false");
            }
            else{
                req.setAttribute("status","true");
                req.setAttribute("userid",user.getUserid());
                req.setAttribute("username",user.getUsername());
                System.out.println("userid:"+user.getUserid());
                System.out.println("username:"+user.getUsername());
                req.getRequestDispatcher(path).forward(req,resp);
                return ;
            }
        }catch(Exception e ){
            e.printStackTrace();
        }
    }
    if(err.size()!=0){
        req.setAttribute("err",err);
    }

    req.getRequestDispatcher(path).forward(req,resp);

}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    this.doGet(req,resp);
}

}

what result do you expect? What is the error message actually seen?

I want to get some of the information I set at the front end. The program can run but can"t get it. The front end can get

through the request.getParameter () function.
May.14,2021

has been solved, carelessness and unclear concept, we still need to work hard!

Menu