问题
I am new to j_security_check tomcat. However i implemented login functionality(form based authentication) using login filter & some settings in web.xml. When we trying to access a secured page, tomcat redirects to login page. After providing credentials it redirects user to a page which user tried to access. So far it is working as expected.
But, the new requirement is: User access a non-secured page (public page), there he can enter his login username & login password. On submitting this page we have to do
- create a user with details provided by the user(save to DB)
- auto login the user and redirect to a secured home page.
the 1st point has already been implemented and working fine. After inserting new user i am redirecting to secured home page. Then container shows a login page where user can enter his credentials, the submit action of login page takes user to secured page.
But i want to redirect user to secured home page after saving his details to DB as we have his username & password i.e. non-secured page to secured page without login page interruption. I want to use container managed authentication only.
Any ideas??
Thanks in advance.
回答1:
If you are using Tomcat 7.0.x and a Servlet 3.0 webapp, you can use the login(user, pass) method of the HttpServletRequest object in your Servlet or Filter.
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#login(java.lang.String,%20java.lang.String)
来源:https://stackoverflow.com/questions/14191751/auto-login-with-j-security-check