• 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

Struts2 Interceptor Error in struts.xml file

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
place interceptor declaration in struts.xml within package declaration.
 
Rushabh Vashi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i do the same thing...and its working....thnx bro..
 
reply
    Bookmark Topic Watch Topic
  • New Topic