aspose file tools*
The moose likes Struts and the fly likes Filter or ActionServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Filter or ActionServlet" Watch "Filter or ActionServlet" New topic
Author

Filter or ActionServlet

Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
hi guys

iam having doubt wether the request goes first

to Filter or ActionServlet if i configure a filter

in my web.xml

and aslo suggest me how to trace it out

regards
amir
Mahesh Desai
Ranch Hand

Joined: Apr 04, 2007
Posts: 76
It depends on how you configure filter in web.xml file. If you configure filter for ActionServlet then each and every request would certainly go through that configured filter. You could debug the app to find out whether it is going through Filter or not. Following is the code from web.xml to configure the Filter for ActionServlet.


<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<servlet>

<filter>
<filter-name>TestFilter</filter-name>
<filter-class>com.xyz.TestFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>TestFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


Thanks,
Mahesh

------------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
thanks for your reply mahesh

in my web.xml it is configured like this

<filter>
<filter-name>Hibernate Filter</filter-name>
<filter-class>com.org.HibernateFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Hibernate Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

insted of <servlet-name> <url-pattern> has been used i want to know

how the request will go either through ActionServlet to filter

or vice versia

regards
amir
Rohit Passi
Greenhorn

Joined: Apr 05, 2007
Posts: 2
As per your web.xml the request will first go to Filter then ActionServlet,
give a look to j2ee design pattern blueprint java.sun.com site.
<br>
There you can see the sequence that follows, the intercepting filters fowards the request to front controller
[ April 05, 2007: Message edited by: Rohit Passi ]
Mahesh Desai
Ranch Hand

Joined: Apr 04, 2007
Posts: 76
Amir,

For your web.xml cofiguration, each request will go through the HibernateFilter.

Rohit's point is correct.

Thanks,
Mahesh

------------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
hi guys

is filters are execueted in the order they have configured in the web.xml

is it possible if i want to change the sequence of filter without

altering the web.xml.by doing programatically
[ May 30, 2007: Message edited by: Amirtharaj Chinnaraj ]
Abhilash George
Greenhorn

Joined: Apr 28, 2006
Posts: 13
J2EE Level 1.2 includes a Servlet Specification level of 2.2 and a JSP Specification level of 1.1. Features such as Servlet Filters and Life Cycle Event Listeners cannot be be used if this level is chosen. Applications developed for this J2EE level 1.2 typically target a WAS version 4.x server.
In such cases you can add filters but they would only get execute after your ActionServlet

If you are using J2EE Level 1.3 includes a Servlet Specification level of 2.3 and a JSP Specification level of 1.2 then first filter and then ActionServlet get executed..


regards


george
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
george thanks for your reply

what my questions is ?

is it possible to change the sequence of the filter execution

by programming a filter or using some other servlet . i have analysed

that filters are execuited according to the hirerchey

in web.xml

looking for your replies
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi Amritharaj,

I dont think so you can be able to change the order of execution of filters because all you have is doFilter() method for passing it onto the next Filter in the chain, which inturn being implemented by the container with the content of webxml.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter or ActionServlet