It is hard to answer the question because I see some inconsistency in your explanations or they are not complete. However, I will take a chance to guess the true and give an answer.
Default login flow is well described in https://stackoverflow.com/a/9530082.
You open web page, server displays login form. When you send password, server opens the page. That is a reason why back button works: you asked the same page twice, but first time login form was displayed. When you click 'Back' after login, then you go back to the same page (the same URL).
You wrote: "Even if (...) the url of the login page is manually typed, the user is shown the main page." That is impossible unless you made custom code that if user is already logged then main page is displayed. By default servlet specification do not block display login page for already logged ones.
So if you have protection against display-login-form-for-logged simply apply it against display-signup-form-for-logged.
The simplest solution I verified is servlet in front of signup form. If user is not logged, follow to JSP with the signup form. If user is logged, redirect to main page. It is important to add resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); otherwise on back button servlet will not be called and browser will display cached form.
If you are still interested, let me know and I will share github example. But I think my explanation is enough to understand and win your problem. (My example is rather not perfect because plain servlet authentication is complicated and I'm used to Spring security)