I didn’t find anything about this or it’s being too hard for me to find…
In my login.jsp I have the action:
<form action="login" method="post">
In my Web.xml I have the mapping:
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.example.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
So, when login fails, my servlet forwards to the same page with typical message. But then the URL gains a /login from the action.
I remember that in plain HTML an empty action would keep the URL unchanged, but in JSP it isn’t allowing me to map the action for the servlet (most of the logical mapping attempts just screws the CSS).
All I want is to keep the same URL after processing the request to self. Any way to do this?
Don’t make the login the welcome file. Make the home page the welcome file (or make the welcome page simply redirect to the home page). This is what users expect to find at the root of the webapp: the home page.
If the home page is accessible only after login, then use a filter to intercept all the requests, and redirect to the login servlet if not logged in. Make the GET request to this servlet display the login page (by forwarding to login.jsp), and the POST request to this servlet handle the login, and forward to the login.jsp again if the login failed.