简体   繁体   中英

doPost skipping response.sendRedirect()

I'm sending a user to a servlet Login where the doPost method is:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("hit login doPost");
    response.sendRedirect("account.jsp");
}

It prints "hit login doPost" when I debug, but skips right over the second line where I'm wanting to redirect. Here is my form (this is on index.jsp page):

<form action="Login" method="post">
    <button type="submit">Login</button>
</form>

Does anyone know what's going on here?

With a combination of stopping tomcat, removing the project from the local tomcat server in eclipse, right clicking on the project name and 'Build Project', and re-running on the server it finally worked. I was simply restarting the server, and I guess it wasn't rebuilding with my changes automatically.

So, to clarify I took these steps to ensure my dynamic web project took servlet changes:

  1. Stop local Tomcat server
  2. Remove the project under "Servers" tab in eclipse
  3. Right click on the project in Package or Project Explorer
  4. Build Project
  5. Right click on server, and Run As Server again

For some reason, it wouldn't take changes unless I've done every single step above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM