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

Need Help about Interceptors in Struts2

Rushabh Vashi
Greenhorn

Joined: Apr 27, 2011
Posts: 20
Hello friends,

I am trying to create my application and need help of interceptors.

I have created Interceptor class named
InterceptorExample

package example;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class InterceptorExample implements Interceptor
{

private static final long serialVersionUID = 1L;

public String intercept(ActionInvocation in) throws Exception
{

String className = in.getAction().getClass().getName();
long startTime = System.currentTimeMillis();

System.out.println("Before calling action: " + className);

String result = in.invoke();

long endTime = System.currentTimeMillis();
System.out.println("After calling action: " + className + " Time taken: " + (endTime - startTime) + " ms");

return result;
}

public void destroy()
{
System.out.println("Destroying Interceptor...");
}
public void init()
{
System.out.println("Initializing Interceptor...");
}
}



My struts.xml file is:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="interceptorTest" class="example.InterceptorExample">
</interceptor>
</interceptors>

<action name="HelloWorld" class="example.HelloWorld">
<interceptor-ref name="interceptorTest"></interceptor-ref>
<result>/example/HelloWorld.jsp</result>
</action>

</package>

</struts>



Now when i am trying to run my project on tomcat..it runs fine but I am not having any effects of interceptors.

What should i do to create workable from interceptors???

Is there any chances in struts.xml file or Interceptor class???

Please help me i m stuck
Rupesh Mhatre
Ranch Hand

Joined: Apr 29, 2011
Posts: 35

do you see your sop on console
Rushabh Vashi
Greenhorn

Joined: Apr 27, 2011
Posts: 20
No i cant see my SOP...
but i found another way to get to know that interceptors are being called or not...
I just returned STATUS from intercept()...
and in struts.xml file i set <result=STATUS>somepage.jsp</result>

and its working....
yepiiiiiiiiii
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help about Interceptors in Struts2