Reputation: 65
I have one abc.jsp page. I have an image on that page. On clicking that image, I need to check for user already logged in or not. If yes, I need to display xyz.jsp. If not, I need to ask the user to login. On success, again I need to go to xyz.jsp.
I am using Struts2.
Help me in this issue.
Upvotes: 0
Views: 126
Reputation: 4239
Here is simple steps(Without interceptor):
1) Define action in struts.xml file :
<action name="CheckUserDtl"
class="com.user.CheckUserDtl">
<result>/WEB-INF/user/xyz.jsp</result>
</action>
2) in your abc.html page- onclick of image button call CheckuserDtl action
3) Write your authentication code in com.user.CheckUserDtl
action file:
Example :
@Override
public String execute()
{
//write code authentication code here
return SUCCESS;
}
Note: Better way is to use interceptors for authentication.
Upvotes: 1
Reputation: 4490
You may use interceptors for your purpose. Interceptors will help you to perform tasks like authentication check, logging..etc before and after each request.
Following link will may be useful for you to implement authentication in struts2.
http://www.journaldev.com/2210/struts-2-interceptor-tutorial-with-custom-authentication-interceptor-example
Upvotes: 3