File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes input values like name= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "input values like name="" can not be populated to interceptors" Watch "input values like name="" can not be populated to interceptors" New topic

input values like name="" can not be populated to interceptors

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79

In my Strut2 application I have to pass uservo.userId and uservo.password to AuthenticationInterceptor's intercept method.

UserVO is a model object that has userId and password properties.


<s:textfield theme="simple" name="uservo.userId" cssClass="LoginTextBox" size="20" />

<s:password theme="simple" name="uservo.password" cssClass="LoginTextBox" size="20" />

when the page is submitted, AuthenticationInterceptor will be invoked to do authentication for checking userId and password entered by the user.

public class AuthenticationInterceptor extends AbstractInterceptor implements SessionAware,RequestAware{

private UserVO uservo;
private String userId;

private String password

UserServices userServices=new UserServicesImpl();
Map<String,Object> session;
Map<String,Object> request;

public void setSession(Map session) {
this.session = session;
public void setRequest(Map request) {
this.request = request;

public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Inside AuthenticationInterceptor");
log.debug(" Inside AuthenticationInterceptor ");
ActionContext ctx = invocation.getInvocationContext();

session = ActionContext.getContext().getSession();

log.debug(" ActionContext ctx :"+ctx);
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
log.debug(" HttpServletRequest request :"+request);

String userIPAddress = request.getRemoteAddr();
String loginID = "anonymous";


if (authenticateCoinUser(request))
loginID = (String)session.get("userId");
if(loginID == null || loginID.trim().equals("")){
loginID = "anonymous";
log.debug("loginId and IP :"+loginID+" : "+userIPAddress);
if(userServices.enlistUserProfile(loginID, userIPAddress)){
return invocation.invoke();
throw new AuthenticationException("You are not authorised");
return null;

public boolean authenticateCoinUser(HttpServletRequest request){

System.out.println(" uservo >>"+uservo);
String userId=getUserId();
String password=getPassword();
System.out.println(" userId >>"+userId);
System.out.println(" password >>"+password);

return false;

public UserVO getUservo() {
return uservo;

public void setUservo(UserVO uservo) {
this.uservo = uservo;

public String getUserId() {
return userId;

public void setUserId(String userId) {
this.userId = userId;

I could not get the uservo.userId and uservo.password input values from index.jsp to the interceptor even i implement RequestAware.

uservo object throws NullPointerException.

Could anybody tell the answer?

David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
David Newton

Joined: Sep 29, 2008
Posts: 12617

1) Interceptors are not actions, and are not treated as such: request parameters are not set on interceptors, and doing so would be a potential nightmare. Ideally, interceptors are completely ignorant of other interceptors in the interceptor stacks.

2) This is an inappropriate use of an interceptor: interceptors are designed to handle cross-cutting application concerns, not logging someone on. Logging someone on should be handled by an action. *Checking* if someone is logged on would be handled by an interceptor.
I agree. Here's the link:
subject: input values like name="" can not be populated to interceptors
It's not a secret anymore!