I started to integrate struts 2 with tiles on IntelliJ environment.
I searched several tutorial on the web, but I still see some wierd symbol not found issue.
This is the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="2.5">
<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>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
</web-app>
This is tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/header.jsp"/>
<put-attribute name="menu" value="/menu.jsp"/>
<put-attribute name="body" value="/body.jsp"/>
<put-attribute name="footer" value="/footer.jsp"/>
</definition>
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="Welcome"/>
<put-attribute name="body" value="/welcome.jsp"/>
</definition>
<definition name="friends" extends="baseLayout">
<put-attribute name="title" value="Friends"/>
<put-attribute name="body" value="/friends.jsp"/>
</definition>
<definition name="office" extends="baseLayout">
<put-attribute name="title" value="Office"/>
<put-attribute name="body" value="/office.jsp"/>
</definition>
</tiles-definitions>
Both tiles and web.xml under WEB-INF directory.
This is struts.xml under src directory:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="FirstWebApp" extends="struts-default">
<result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types>
<action name="*Link" method="{1}" class="hello.HelloWorld">
<result type="tiles" name="welcome">welcome</result>
<result type="tiles" name="friends">friends</result>
<result type="tiles" name="office">office</result>
</action>
</package>
</struts>
I am getting four errors, I think they below to two different groups:
Error:(12, 13) Cannot resolve symbol 'welcome'
Error:(13, 13) Cannot resolve symbol 'friends'
Error:(8, 42) Cannot resolve package 'struts-default'
Error:(14, 13) Cannot resolve symbol 'office'
For error 3, if I add struts-default.xml from internet, I saw a bunch of other class not found error related to com.opensymphony.xwork2 package.
For error 1, 2, and 4, I don't know how to let struts.xml to look at the tiles.xml to solve the symbol.
Thanks in advance for help.
Remove name="welcome" name="friends" name="office" and use "tiles-default" instead of "struts-default"
Related
I was trying to write a simple Struts 2 program.
In the struts.xml I am getting the error
The file cannot be validated as there was a connection problem.
My struts.xml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<action name="hello"
class="hello.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</struts>
JAR files are
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.9.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.3.jar
xwork-core-2.3.16.3.jar
You forgot the <package> element, and DTD should be 2.3:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello"
class="hello.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
I am trying to integrate Tiles3.0.3 with Struts2, but I am getting java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException.
Here is my web.xml
<web-app version="3.0" 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_3_0.xsd">
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>example/HelloWorld.jsp</welcome-file>
</welcome-file-list>
</web-app>
And here is my tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="banner" value="/banner.jsp"/>
<put-attribute name="menu" value="/menu.jsp"/>
<put-attribute name="body" value="/body.jsp"/>
<put-attribute name="footer" value="/footer.jsp"/>
</definition>
<definition name="tiger" extends="baseLayout">
<put-attribute name="title" value="Tiger"/>
<put-attribute name="body" value="/tiger.jsp"/>
</definition>
<definition name="lion" extends="baseLayout">
<put-attribute name="title" value="Lion"/>
<put-attribute name="body" value="/lion.jsp"/>
</definition>
</tiles-definitions>
And these are the errors I am getting
SEVERE: Error configuring application listener of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.NoClassDefFoundError: org/apache/tiles/web/startup/TilesListener
Caused by: java.lang.ClassNotFoundException: org.apache.tiles.web.startup.TilesListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 52 more
And these are the jars which I am using :-
commons-beanutils-1.8.2.jar,commons-digester-1.7.jar,struts2-tiles-plugin-2.2.3.1.jar,
tiles-api-3.0.3.jar,tiles-compat-3.0.3.jar, tiles-core-3.0.3.jar, tiles-jsp-3.0.3.jar,tiles-servlet-3.0.3.jar
Please help me out.
You need to have tiles jar in your web-inf/classes.
If your project is maven enabled use below:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.3.16.1</version>
</dependency>
Or download struts-tiles plugin and tiles plugin jars manualy
I am developing a Dynamic Web Application, using JSF 2.2, Spring Framework 4.0 and Spring Security 3.2. I, first, integrated JSF and Spring framework (JSF Page => ManagedBean => Service => DAO). It was working fine. But when I introduced Spring Security, I am unable to access ManagedBean in JSF page and getting no error at all. ManagedBean is not even invoked (even constructor is not called). I have been surfing for this issue for 2 days now, but couldn’t find any resolution.
My config files are as following:
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>my-app-ui</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Spring Framework -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Spring context config locations -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext.xml</param-value>
<param-value>classpath*:/securityConfig.xml</param-value>
</context-param>
<!-- PROJECT STAGE START FOR DEVELOPEMENT MARK IT AS DEVELOPMENT. FOR TESTING / PRODUCTION REMOVE THIS -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- JSF -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
applicationconContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="com.myapp.managedbean"/>
<context:component-scan base-package="com.myapp.service"/>
<context:component-scan base-package="com.myapp.domain"/>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/myDS" />
</bean>
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
securityConfig.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd ">
<debug />
<http pattern="/resources/**" security="none" />
<http pattern="/login*" security="none" />
<http auto-config="true" use-expressions="true" disable-url-rewriting="true" >
<intercept-url pattern="/**" access="authenticated" />
<form-login authentication-failure-url="/loginfailed.html"
default-target-url="/" always-use-default-target="true"/>
<access-denied-handler error-page="/denied.html"/>
<session-management invalid-session-url="/session-expire.html" session-fixation-protection="none" />
<logout delete-cookies="JSESSIONID" invalidate-session="true" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user_admin" password="password" authorities="ROLE_USER,ROLE_ADMIN" />
<user name="user" password="password" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</b:beans>
first-jsf-page.xhtml
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
</head>
<body>
Managed bean data: #{myMB.fetchDataFromService()}
</body>
</html>
ManagedBean
#Component("myMB")
#Scope("session")
public class MyMB implements Serializable {
public MyMB () {
System.out.println("Constructor called");
}
#Autowired
#Qualifier("myService")
public MyService myService;
Public String fetchDataFromService() {
System.out.println("Invoking Service");
return myService.getMessage();
}
}
MyService
public interface MyService {
public String getMessage();
}
MyServiceImpl
#Service("myService")
public class MyServiceImpl implements MyService {
#Override
public String getMessage() {
return "JSF and Spring Integrtion - Done";
}
}
If I remove "DelegatingFilterProxy" from Web.xml, everything works fine. Kindly help me out here.
I am using Eclipse and tomcat server.
I upgraded from Struts 2.0.8 to 2.3.15.2
Am getting below error when starting my apache tomcat server.
Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
**INFO: Starting Servlet Engine: Apache Tomcat/6.0.33
Oct 16, 2013 1:03:07 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class
org.apache.struts2.tiles.StrutsTilesListener
java.lang.NullPointerException
at org.apache.commons.digester.Digester.getXMLReader(Digester.java:1058)
at org.apache.commons.digester.Digester.parse(Digester.java:1887)
at org.apache.tiles.definition.digester.DigesterDefinitionsReader.read(DigesterDefinitionsReader.java:267)**
I am using the following jar files in my WEB-INF/lib folder
commons-beanutils-1.8.0.jar
commons-codec-1.6.jar
commons-collections-3.1.jar
commons-dbcp.jar
commons-digester-2.0.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-logging-1.1.3.jar
commons-pool-1.6.jar
crimson.jar
displaytag-1.1.jar
displaytag-export-poi-1.1.jar
fluent-hc-4.2.3.jar
freemarker-2.3.19.jar
httpclient-4.2.3.jar
httpclient-cache-4.2.3.jar
httpcore-4.2.2.jar
httpmime-4.2.3.jar
itext-2.0.4.jar
javax.mail_1.4.0.v201005080615.jar
jstl.jar
log4j-12.jar
mail.jar
ognl-3.0.6.jar
ojdbc6.jar
poi-3.0.1-FINAL-20070705.jar
standard.jar
struts2-core-2.3.15.2.jar
struts2-tiles3-plugin-2.3.15.2.jar
struts2-tiles-plugin-2.3.15.2.jar
struts-core-1.3.10.jar
tiles-api-2.0.6.jar
tiles-core-2.0.6.jar
tiles-jsp-2.0.6.jar
xwork-core-2.3.15.2.jar
WEB.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>My Web Application</display-name>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>
org.displaytag.filter.ResponseOverrideFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<listener>
<listener-class>com.comp.ccra.listener.CCRAContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
STRUTS.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="ccra" extends="struts-default" >
<interceptors>
<interceptor name="login" class="com.comp.ccra.action.interceptor.LoginInterceptor"/>
<interceptor-stack name="defaultLoginStack">
<interceptor-ref name="login"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- Make the defaultLoginStack the default one used
for all actions unless otherwise configured. -->
<default-interceptor-ref name="defaultLoginStack" />
<global-results>
<result name="exception">/WEB-INF/jsp/exception.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="org.apache.tomcat.dbcp.dbcp.SQLNestedException" result="exception"/>
<exception-mapping exception="javax.servlet.ServletException" result="exception"/>
<exception-mapping exception="java.sql.SQLException" result="exception"/>
<exception-mapping exception="java.lang.Exception" result="exception"/>
</global-exception-mappings>
</package>
<include file="struts-filedownload.xml" />
<include file="struts-fileupload.xml" />
<include file="struts-common.xml" />
<include file="struts-report.xml" />
<include file="struts-admin.xml" />
</struts>
TILES.xml
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<!-- Definitions for Tiles documentation -->
<tiles-definitions>
<!-- ======================================================= -->
<!-- Master definition -->
<!-- ======================================================= -->
<definition name="basicLayout" template="/WEB-INF/tiles/layout/basicLayout.jsp">
<put-attribute name="title" value="Call Center Connection (C3)"/>
<put-attribute name="header" type="template" value="/WEB-INF/tiles/layout/header.jsp"/>
<put-attribute name="navigation" type="template" value="/WEB-INF/tiles/layout/navigation.jsp"/>
<put-attribute name="body" type="template" value="/WEB-INF/tiles/layout/empty.jsp"/>
<put-attribute name="info" type="template" value="/WEB-INF/tiles/layout/info.jsp"/>
<put-attribute name="footer" type="template" value="/WEB-INF/tiles/layout/footer.jsp"/>
</definition>
<definition name="homePage" extends="basicLayout" >
</definition>
</tiles-definitions>
Please suggest if i am doing anything wrong here. Any help is greatly appreciated.
You cannot mix two different Tiles versions, use either struts2-tiles3-plugin-2.3.15.2.jar or struts2-tiles-plugin-2.3.15.2.jar.
And follow the docs depending on Tiles version:
http://struts.apache.org/release/2.3.x/docs/tiles-plugin.html
http://struts.apache.org/release/2.3.x/docs/tiles-3-plugin.html
I'm trying to get my Struts2 project running with Tiles and REST Plugin but I just can't get it working.
I've looked at the documentation for both and I think i'm doing it right. here are my files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app metadata-complete="true" 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">
<!-- listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<!-- context params -->
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles-tradesman.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-tradesman.xml</param-value>
</context-param>
<!-- filters -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- filter mappings -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="tp"/>
<package name="tradesman" namespace="/beta/tradesman" extends="default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
</struts>
JobAlertsController.java
package uk.co.ratedpeople.tp;
import com.opensymphony.xwork2.ActionSupport;
import java.util.logging.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
public class JobAlertsController extends ActionSupport {
private static final Logger LOGGER = Logger.getLogger(JobAlertsController.class.getName());
#Action(results={
#Result(name = SUCCESS, location = "tradesman.page.jobalerts", type = "tiles")
})
public String index() {
LOGGER.info("executing index action...");
LOGGER.info("leaving index action...");
return SUCCESS;
}
}
When i try to run the project I get this error:
SEVERE: Exception starting filter struts2
Unable to load configuration. - [unknown location]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:195)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4542)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5220)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5215)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)
... 13 more
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class uk.co.ratedpeople.tp.JobAlertsController] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [uk.co.ratedpeople.tp#rest-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:427)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:399)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:200)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:864)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:650)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:335)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 15 more
27-Jul-2011 17:07:07 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
I'm sure i'm doing something really stupid but I can't see it myself. Anyone?
First, I would suggest putting your struts actions in a package simply called struts, I've had much less configuration issues when using standard conventions plugin architecture. Move your actions to a package like:
uk.co.ratedpeople.struts
instead of
uk.co.ratedpeople.tp;
The less out of the box configuration, the better off you typically are.
This also eliminates the need for this:
<constant name="struts.convention.package.locators" value="tp"/>
Second, part of your problem is with your xml configuration:
<struts>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="tp"/>
<package name="tradesman" namespace="/beta/tradesman" extends="default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
Try something like this instead (providing you moved your actions as previously suggested):
<struts>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="tradesman"/>
<package name="tradesman" namespace="/beta/tradesman" extends="rest-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
</package>
</struts>
Notice the constant name="struts.convention.default.parent.package" value="tradesman" which is referring to the package below it which defines your result types and extends rest-default. This should eliminate your tiles result definition errors.
I've also run into issues using the struts filter you have in your web.xml, I would change from:
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
to:
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>