File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts 2 Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 Question" Watch "Struts 2 Question" New topic

Struts 2 Question

Vinayak Jallapelli

Joined: Feb 27, 2008
Posts: 11
I am doing task on struts2. In that I have to use custom AutherizationInterceptor. In my custom Interceptor Im checking weather user is in session or not. And if he tries to attempt login I gave parameter in struts.xml as true So Im checking against it and interceptor redirects action to Home. But my problem is unable to get the request parameters in Home Action class.
Please help me I need to implement this code in my project.

My code is-------

In struts.xml for Login Attemp

<action name="home" class="com.mss.HomeAction">

<interceptor-ref name="authorizationInterceptor">
<param name="loginAttempt">true</param>

<result name="input">login.jsp</result>
<result name="login">login.jsp</result>
<result name="success">home.jsp</result>

My Interceptor -------

public class AutherizationInterceptor implements Interceptor,StrutsStatics {

//private HttpServletRequest httpServletRequest;
private boolean loginAttempt;
/** Creates a new instance of AuthorizationInterceptor */
public AuthorizationInterceptor() {
public void destroy() {
public void init() {

public String intercept(ActionInvocation actionInvocation) throws Exception {

final ActionContext context = actionInvocation.getInvocationContext();

Map session = context.getSession();
Action action = null;

if(loginAttempt) {
return actionInvocation.invoke();
} else {
if(session.get("userName") != null){
action = ( Action ) actionInvocation.getAction();
return actionInvocation.invoke();
} else {
return Action.LOGIN;

public void setLoginAttempt(boolean loginAttempt) {
this.loginAttempt = loginAttempt;

My Action Class*****

public String execute() {
resultType = SUCCESS;

String userName = getUserName();
System.err.println("hai ********");
String password = getPassword();
if(userName!=null && password != null) {
resultType = SUCCESS;
} else {
resultType = INPUT;
return resultType;

Thanks in advance...

Best Regards,<br />Vinayak Jallapelli
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Have you taken a look at this?
[ April 29, 2008: Message edited by: Chengwei Lee ]

SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
chad michael davis

Joined: Mar 01, 2006
Posts: 27
The parameter you set is auto-injected into the interceptor itself. Not the action. Do I misunderstand something?

Chad Davis<br />Co-author of Struts 2 in Action
I agree. Here's the link:
subject: Struts 2 Question
jQuery in Action, 3rd edition