File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Filter being called for Struts' forwarded JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter being called for Struts Watch "Filter being called for Struts New topic
Author

Filter being called for Struts' forwarded JSP

Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
I have a Struts action class like this:



A filter like this:



My struts-config.xml:



My filter declaration in web.xml:



My test.jsp JSP is like this:



When I called the action, I got the following result:

requestUri: /TestAction.do
In TestAction
requestUri: /test.jsp
In test.jsp
After
After

My question is: why is the filter called for the JSP? I thought only request that is coming in directly from the client browser will activate the filter, which in this case should be for /TestAction.do only.

By the way, I am using BEA WebLogic 8.1 to test this.


SCJP 1.2, SCWCD 1.4
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
The Java Servlet specification version 2.3 introduces a new component type, called a filter. A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.

From Essential of Filters
Filter is used for intercepting both request and response.

try using /*.do for mapping


SCJP 1.4
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Vivek Kr Singh wrote:try using /*.do for mapping


hi Vivek , what is the difference between /*.do and *.do ?
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
Sorry thats a mistake it should be *.do.

/*.do will be an invalid pattern
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
Hi guys, I think you are missing the point. I want my filter to be activated for ALL requests coming from the client browser, not just .do only.

My point is, why is the filter activated for a forward? The JSP request does not come directly from the dlient; it is a forwarded request. From what I read from the specification, by default the filter should only be activated for requests coming directly from the client. I have explicitly stated this with <dispatcher>REQUEST</dispatcher> too. But it seems to have no effect.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
Edmund Said:
From what I read from the specification, by default the filter should only be activated for requests coming directly from the client. I have explicitly stated this with <dispatcher>REQUEST</dispatcher> too.

I had a look at the Dispatcher element schema, here is what it mentions
The dispatcher has four legal values: FORWARD, REQUEST, INCLUDE and ERROR. A value of FORWARD means the Filter will be applied under RequestDispatcher.forward() calls. A value of REQUEST means the Filter will be applied under ordinary client calls to the path or servlet. A value of INCLUDE means the Filter will be applied under RequestDispatcher.include() calls. A value of ERROR means the Filter will be applied under the error page mechanism. The absence of any dispatcher elements in a filter-mapping indicates a default of applying filters only under ordinary client calls to the path or servlet.

By default filter will be applied to the path or servlet. Path like "/*" means filter will be applied to everything after the context.
Maybe some one else can explain why REQUEST in Dispatcher does not prevent filter from being applied on actionMapping.findForward("test");
What are ordinary Client calls apart from client browser?
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
I think the <dispatcher> tag is applicable from servlet 2.4 onwards. On WebLogic 8.1, I believe that it is implementing servlet 2.3, which does not have this <dispatcher> tag. And therefore, the filter will be applied to everything. Can anyone confirm this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter being called for Struts' forwarded JSP
 
Similar Threads
Can't get my login servlet to be called
JSP Filter with Struts
Coding SuccessServlet
Tomcat servlet-mapping bypass if real file requested
Filter Problem