GeeCON Prague 2014*
The moose likes Struts and the fly likes interceptor problem in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "interceptor problem in struts2" Watch "interceptor problem in struts2" New topic
Author

interceptor problem in struts2

sanjoy sa
Greenhorn

Joined: Aug 19, 2009
Posts: 9
while using interceptors in struts 2 I got the following error. I used myeclipse8.5 IDE. Please advice


Aug 19, 2010 5:29:54 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Dispatcher initialization failed
Caused by: Unable to find interceptor class referenced by ref-name model-driven - interceptor-ref - file:/D:/saaj/.metadata/.me_tcat/webapps/Struts2Application/WEB-INF/classes/struts.xml:49:43
at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:52)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:987)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildInterceptorList(XmlConfigurationProvider.java:539)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:370)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:468)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:264)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 18 more
SEVERE: Exception starting filter struts2
Unable to load configuration. - interceptor-ref - file:/D:/saaj/.metadata/.me_tcat/webapps/Struts2Application/WEB-INF/classes/struts.xml:49:43
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
.
.
.
.


My struts.xml is as follows

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<include file="struts-default.xml"></include>
<package name="default" extends="struts-default">
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="exception" />
</global-exception-mappings>

<action name="modelAction" class="com.kogent.action.ModelAction">
<interceptor-ref name="exception" />
<interceptor-ref name="prepare" />
<interceptor-ref name="debugging" />
<interceptor-ref name="model-driven" />
<interceptor-ref name="params" />
<interceptor-ref name="conversionError" />
<interceptor-ref name="workflow" />
<result name="success">/student_info.jsp</result>
<result name="error">/model.jsp</result>
<result name="exception">/exception.jsp</result>
<result name="input">/model.jsp</result>
</action>
</package>
</struts>



My web.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


My ModelAction.java is as follows


package com.kogent.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ModelAction extends ActionSupport implements ModelDriven, Preparable {

private Student student;


public void prepare(){
student=new Student();
}
public Object getModel(){
return student;
}
public String execute() throws Exception {

if(student.getPassword().length()>=6)
return SUCCESS;
else{
this.addActionError(getText("app.invalid.password.length"));
return ERROR;
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The name of the interceptor is "modelDriven"; the error message is telling you precisely what's wrong.
sanjoy sa
Greenhorn

Joined: Aug 19, 2009
Posts: 9
Thanks David. Where exactly I will get the interceptors in the library
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not sure what you're asking. The interceptors are defined in the struts-default.xml config file. Their names are also documented on the Struts 2 documentation site.
 
GeeCON Prague 2014
 
subject: interceptor problem in struts2