Meaningless Drivel is fun!
The moose likes Struts and the fly likes use of interceptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "use of interceptor" Watch "use of interceptor" New topic

use of interceptor

Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131

I am using Struts2.0, Tomcat5.5 on windows XP system.

I am trying to keep track of time taken by a action class. For this I am trying to use interceptor. I specify this in the strus.xml as The interceptor is defined in the struts.xml as Now the Interceptor code is as As can be seen in the code I am trying two ways to get this timeTaken value to the result="success" JSP page

1. Via bean property i.e. private String ruleRunTimeTaken;
2. Via putting it in session attribute MyTime

Now in the result JSP I am trying to access this time taken as Here the bean property way is not working at all. I am getting blank always. May be this is not the correct way to do it. Please suggest how to get the timeTaken value across to the JSP page from Interceptor class.

Now the session thing sometimes work sometimes not. i.e. sometime I get the timeTaken value and other time it is blank. I am really confused

Please help me understand this. Thanks in advance for taking time out to help me.

Programmer Analyst || J2EE web development/design
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

I'm not sure if your logic is correct. The execution time can be calculated only after the action has been invoked. In that case, what you put in a session can only be displayed by the next invocation. This is the reason why the first invocation always displays the blank and subsequently, it'll display the previous execution time.

SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Thanks Freddy for pitching in. So how do you think shall I get this done. I want it to be configurable- as later on, I see myself tracking this timeTaken thing for other action classes.

What is the difference between Filter and Interceptor; shall I use Filter in this scenario.

One more thing- does the bean property set in the interceptor, set on ValueStack and subsequently can be accessed on the JSP pages using ELs.
David Newton

Joined: Sep 29, 2008
Posts: 12617

There's already a timer interceptor in S2, btw.
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
David thanks for the response. This link I was looking at
Here it says that the time taken will be logged in a file. I want this information to be in the valueStack and something that I can use on the response page that will be decided by the value of return string from the Action class's execute(or other method). We want to measure the time taken in the processing of this method in the Action class.

But someone here truly said that by the time the interceptor is getting the end time and the difference i.e. timeTaken the response has alraedy been committed. So how to get this value to the JSP page. Another question - if we have an instance variable in the Interceptor class and we have getter and setter for that in the interceptor class - will they be put on the valueStack similar to what happen in case of Action classes.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: use of interceptor
It's not a secret anymore!