Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts using ServletConfigInterceptor for accessing the HttpServletRequest. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts using ServletConfigInterceptor for accessing the HttpServletRequest." Watch "Struts using ServletConfigInterceptor for accessing the HttpServletRequest." New topic
Author

Struts using ServletConfigInterceptor for accessing the HttpServletRequest.

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

First of all hi to all Ranchers ,



Is implementing the ServletRequestAware is not sufficient for accessing the ServleRequest .

why do we need a ServletConfigInterceptor interceptor to associate with the action ??


If you want something you never had do something which you had never done
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The interceptor is what calls setServletRequest() to actually set the servlet request.

Note that directly accessing the servlet request ties your class to the servlet spec and makes it less testable--in general you rarely need to do this.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks David ,

After refering to the some sites i saw that implementing Aware interfaces in for access resources is a bad approach , and the best would be use the Spring Framework IOC for getting all these things to be done .

Is this would be the right approach ??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That would depend on what resources you're trying to access.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528

Generally these resources like Request ,Response , Context , and Config are sufficient know to work (Correct me please if i am wrong).

And also i want to use Hibernate as ORM , so i will mention all these like in a ApplicationContext XML file.

Will this be a correct approach ??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Again: it should be rare that you need to access the request (or response) directly in S2.

"Context" means nothing by itself; I don't know what context you're talking about. Same with "Config".

If you have Spring questions, ask them in the Spring forum.
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
"Again: it should be rare that you need to access the request (or response) directly in S2."


This is waht i am looking for.
Thanks once again.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Okay, but that doesn't really have anything to do with Spring or the original question regarding the interceptor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts using ServletConfigInterceptor for accessing the HttpServletRequest.
 
Similar Threads
Struts 2 session writing efficiency / timing
struts 2: how can i pass a Vector as a parameter?
Session checking with Struts 2
Struts2 - Using ServletRequestAware is ok if we have multiple methods in action class?
How can Action class will get access to HttpServletRequest to access data??