[STRUTS2] Get request object in Interceptor?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bobby_s
Posted On:   Monday, July 28, 2008 06:10 AM

Hi I am trying to get hold of the HttpServletRequest object in my interceptor (which applies to all my actions). However, it returns null . I am using the same method in an action and am able to get the request object successfully. Is the request object not available in an interceptor? What I am trying to do is get the webapp context path in my interceptor so that I am able to get a text file in one of my directories. So I want the "/myapp" part of "http://localhost:8080/myapp". This is normally achieved by request.getContextPath(), which is why I am trying to get the request object in my interceptor. My interceptor code is below. Thanks in advance.    More>>

Hi



I am trying to get hold of the HttpServletRequest object in my interceptor (which applies to all my actions).



However, it returns null . I am using the same method in an action and am able to get the request object successfully.



Is the request object not available in an interceptor?



What I am trying to do is get the webapp context path in my interceptor so that I am able to get a text file in one of my directories. So I want the "/myapp" part of "http://localhost:8080/myapp". This is normally achieved by request.getContextPath(), which is why I am trying to get the request object in my interceptor.



My interceptor code is below. Thanks in advance.





package com.my.interceptor;



import com.opensymphony.xwork2.ActionContext;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.ActionProxy;

import com.opensymphony.xwork2.interceptor.Interceptor;



import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



import org.apache.struts2.interceptor.ServletRequestAware;

import org.apache.struts2.interceptor.ServletResponseAware;



public class TickerInterceptor implements Interceptor,ServletRequestAware,ServletResponseAware {



   

private static final long serialVersionUID = 1L;



   

private HttpServletRequest request;
   
private HttpServletResponse response;



   

public void destroy() {}
   
public void init() {}




   

public String intercept(ActionInvocation invocation) throws Exception {
      
System.out.println("INTERCEPTING FROM INTERCEPT =============================================");
      
System.out.println("THE REQUEST IS "+request+"===============================================");
      
return "success";
   
}



   

public void setServletRequest(HttpServletRequest arg0) {
      
this.request = request;
   
}


   

public void setServletResponse(HttpServletResponse arg0) {
      
this.response = response;
   
}



   

public HttpServletRequest getServletRequest(){
      
return request;
   
}


   

public HttpServletResponse getServletResponse(){
      
return response;
   
}



}




   <<Less
About | Sitemap | Contact