wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2 Interceptor Error in struts.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Interceptor Error in struts.xml file" Watch "Struts2 Interceptor Error in struts.xml file" New topic
Author

Struts2 Interceptor Error in struts.xml file

Rushabh Vashi
Greenhorn

Joined: Apr 27, 2011
Posts: 20
Hello everyone...

I am creating my application using Struts2 framework...


I have created Interceptor named InterceptorEx ....

code..

package example;

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

public class InterceptorEx 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...");
}
}


struts.xml

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

<struts>

<interceptors>
<interceptor name="interceptorTest" class="example.InterceptorEx">
</interceptor>
</interceptors>

<package name="default" extends="struts-default">
<action name="HelloWorld" class="example.HelloWorld">
<interceptor-ref name="interceptorTest"></interceptor-ref>
<result>/example/HelloWorld.jsp</result>
</action>
<action name="welcome" class="example.Welcome">
<result name="REDIRECT" type="redirectAction">Register.action</result>
<result name="input">/example/welcome.jsp</result>
<result name="SUCCESS">/example/HelloWorld.jsp</result>
<result name="FAILIOUR">/example/welcome.jsp</result>
</action>
<action name="Register" class="example.RegisterAction">
<!--<result name="input">/example/Registration.jsp</result>-->
<result name="SUCCESS">/example/viewRegister.jsp</result>
<result name="POPULATE">/example/Registration.jsp</result>
<result name="ERROR">/example/welcome.jsp</result>
</action>
<action name="Order" class="example.BeanExample">
<result name="SUCCESS">/example/BeanExample.jsp</result>
<result name="FAIL">/example/BeanExample.jsp</result>
</action>

<action name="modelAction" class="example.ModelAction" >
<result name="success">/example/modelView.jsp</result>
</action>


<action name="User" class="example.DispatchActionEx">
<result name="success">/example/DispatchAction.jsp</result>
</action>
<action name="*User" class="example.DispatchActionEx" method="{1}">
<result name="success">/example/DispatchAction.jsp</result>
</action>

</package>

</struts>


now i am gettting errror in XML file.....
if i remove interceptor tags then it works fine.....
please help me friends....
Rupesh Mhatre
Ranch Hand

Joined: Apr 29, 2011
Posts: 35

place interceptor declaration in struts.xml within package declaration.
Rushabh Vashi
Greenhorn

Joined: Apr 27, 2011
Posts: 20
yeah i do the same thing...and its working....thnx bro..
 
 
subject: Struts2 Interceptor Error in struts.xml file