• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use of interceptor

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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.
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's already a timer interceptor in S2, btw.
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David thanks for the response. This link I was looking at
http://struts.apache.org/2.1.6/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/TimerInterceptor.html
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.

 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic