Validation on Redirect

后端 未结 3 1972
死守一世寂寞
死守一世寂寞 2021-01-17 05:28

validation.java

     try
    {
        conn = dsEvent.getConnection();
        String userCheck = \"select * from customer\";
        stmt = conn.createState         


        
3条回答
  •  情歌与酒
    2021-01-17 05:52

    Seems like the ResultSet contains at least two rows, so the server is executing the forward and/or the redirect or a combination of both at least two times, which is not allowed since you're trying to write the response when it's already closed.

    Solution: Move the validation code outside any loop. Make sure the call to RequestDispatcher#forward or HttpServletResponse#redirect occurs once only in your method in servlet.

    Also, I don't recommend using redirect in this case, because it generates a new request/response cycle so all the attributes stored in the request won't pass to this new request/response.

提交回复
热议问题