I think I get a strange condition in struts validation, because sometimes it works and sometimes do not work. I using maven. On the first install, i get it work. But after maven clean, it never work again.
When I install my project (maven install), xml validation (CustomerAction-validation.xml) is not copied to action class package in the target folder. I don't know why.
It will error if I remove <interceptor-ref name="prepare"/> in "customer-form" action. Although I use default-interceptor. No customization.
Other question about login form (unrelated to validation). How to post the form to another namespace. I try by using namespace="/web", but it not work. That's why i try by using s:url, but it make i can't use s:form
This is my project structure
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>struts.test</groupId>
<artifactId>validation</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>validation Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<junit.version>3.8.1</junit.version>
<struts2.version>2.3.1.2</struts2.version>
<struts2-tiles-plugin.version>2.3.14</struts2-tiles-plugin.version>
<tiles.version>2.0.7</tiles.version>
<commons-logging.version>1.1.3</commons-logging.version>
<commons-collection.version>3.2.1</commons-collection.version>
<xwork.version>2.1.3</xwork.version>
<dojo.version>2.1.8</dojo.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Struts 2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>${struts2-tiles-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${tiles.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${tiles.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${tiles.version}</version>
</dependency>
<!-- Struts 2 Dojo Ajax Tags -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-dojo-plugin</artifactId>
<version>${dojo.version}</version>
</dependency>
<!-- Struts 2 JSON Plugins -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${dojo.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork</artifactId>
<version>${xwork.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.19</version>
</dependency>
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<finalName>validation</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
struts.xml
<?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.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/web">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="login" class="struts.test.validation.action.LoginAction">
<result name="success" type="tiles">/welcome.tiles</result>
<result name="error">Login.jsp</result>
</action>
<action name="savecustomer" class="struts.test.validation.action.CustomerAction" method="saveCustomer">
<result name="success" type="tiles">/customer.success.tiles</result>
<result name="input" type="tiles">/customer.tiles</result>
</action>
<action name="customer-form" class="struts.test.validation.action.CustomerAction" method="addCustomer">
<interceptor-ref name="prepare"/>
<result name="success" type="tiles">/customer.tiles</result>
<result name="input" type="tiles">/customer.tiles</result>
</action>
</package>
</struts>
CustomerAction-validation.xml
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="customer.name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="customer.email">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
<field name="customer.type">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="errors.required" />
</field-validator>
</field>
</validators>
CustomerAction class
public class CustomerAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private CustomerDto customer;
private List<String > listCustoType;
public String addCustomer(){
listCustoType = new ArrayList<String>();
listCustoType.add("Type1");
listCustoType.add("Type2");
return SUCCESS;
}
public String saveCustomer() {
System.out.println(customer.getName()+" "+customer.getEmail());
return SUCCESS;
}
public CustomerDto getCustomer() {
return customer;
}
public void setCustomer(CustomerDto customer) {
this.customer = customer;
}
public List<String> getListCustoType() {
return listCustoType;
}
public void setListCustoType(List<String> listCustoType) {
this.listCustoType = listCustoType;
}
}
CustomerDto class
public class CustomerDto {
private Integer id;
private String name;
private String email;
private String type;
//getter & setter
Customer Form
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<body>
<h2>Customer Form</h2>
<s:form action="savecustomer" method="post" validate="true" namespace="/web">
<s:select
label="Customer Type"
list="listCustoType"
name="customer.type"
headerKey="-1"
headerValue=""/>
<s:textfield name="customer.name" key="customer.name" size="20" />
<s:textfield name="customer.email" key="email" size="20" />
<s:submit method="addCustomer" key="label.add.customer" align="center" />
</s:form>
</body>
</html>
Login form
<form action='<s:url value='/'/>web/login' method="post">
<s:textfield name="username" key="label.username" size="20" />
<s:password name="password" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</form>
My complete project I uploaded here
In Maven projects, non-Java artifacts intended to be deployed on the classpath need to be in:
src/main/resources
Because you've placed them in the Java source directory tree they will not be deployed.
In your specific case:
src/main/resources/struts/test/validation/action/CustomerValidation-validation.xml
This is the same pattern as the other XML files in the resources directory, deployed to the classpath.
Just ran into the problem where my validation files were not copying over. To fix this problem, you need to add in the maven-war-plugin and configure it properly to include the XML files. Here is what I added to my pom.xml file to get it working in my project:
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/java/com/project/controller/</directory>
<targetPath>WEB-INF/classes/com/project/controller/</targetPath>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
You can read up more on how the maven-war-plugin works here.
Related
I have a warning highlighted for the element:
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="localSystemServices" />
<rescap:Capability Name="packagedServices" />
</Capabilities>
With the below detail:
The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid
child element 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities'. List of possible elements
expected: 'CapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as
'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10' as well as 'Capability' in
namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/6' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/7' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/3' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/2' as well as 'CustomCapabilityChoice' in namespace
'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'CustomCapability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Dev....
The Package.appmanifest xml manifest is below:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop2="http://schemas.microsoft.com/appx/manifest/desktop/windows10/2"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
IgnorableNamespaces="uap rescap">
<Identity
Name="11d14331-0000-0000-0000-3c2e4cc6d69d"
Publisher="CN=my.name"
Version="1.0.10.0" />
<Properties>
<DisplayName>My Agent</DisplayName>
<PublisherDisplayName>My</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="My Agent"
Description="My Agent."
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<desktop6:Extension Category="windows.service" EntryPoint="Windows.FullTrustApplication" Executable="Agent\Agent.exe">
<desktop6:Service Name="Agent" StartAccount="localSystem" StartupType="auto"/>
</desktop6:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="localSystemServices" />
<rescap:Capability Name="packagedServices" />
</Capabilities>
<Extensions>
<desktop2:Extension Category="windows.firewallRules">
<desktop2:FirewallRules Executable="Agent\Agent.exe">
<desktop2:Rule Direction="in" IPProtocol="TCP" Profile="all"/>
<desktop2:Rule Direction="in" IPProtocol="UDP"
Profile="all"/>
<desktop2:Rule Direction="out"
IPProtocol="TCP"
Profile="all"/>
<desktop2:Rule Direction="out"
IPProtocol="UDP"
Profile="all"/>
</desktop2:FirewallRules>
</desktop2:Extension>
</Extensions>
</Package>
In these moments, I'm trying to configure the IBM wmq.jmsra.rar resource adapter with Wildfly Swarm in a Java project but without success.
Those are the stepts that I've been doing till now:
1) pom.xml (the artifact was installed manually)
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq</artifactId>
<version>7.5.0.8</version>
<type>rar</type>
</dependency>
2) module.xml for this resource adapter (in src/main/resources/modules/com/ibm/wsmq/main):
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:2.0" name="com.ibm.mq">
<resources>
<resource-root path="." />
<resource-root path="com.ibm.mq.commonservices.jar" />
<resource-root path="com.ibm.mq.connector.jar" />
<resource-root path="com.ibm.mq.headers.jar" />
<resource-root path="com.ibm.mq.jar" />
<resource-root path="com.ibm.mq.jmqi.jar" />
<resource-root path="com.ibm.mq.jmqi.local.jar" />
<resource-root path="com.ibm.mq.jmqi.remote.jar" />
<resource-root path="com.ibm.mq.jmqi.system.jar" />
<resource-root path="com.ibm.mq.jms.admin.jar" />
<resource-root path="com.ibm.mq.pcf.jar" />
<resource-root path="com.ibm.mqjms.jar" />
<resource-root path="com.ibm.msg.client.commonservices.j2se.jar" />
<resource-root path="com.ibm.msg.client.commonservices.jar" />
<resource-root path="com.ibm.msg.client.jms.internal.jar" />
<resource-root path="com.ibm.msg.client.jms.jar" />
<resource-root path="com.ibm.msg.client.matchspace.jar" />
<resource-root path="com.ibm.msg.client.provider.jar" />
<resource-root path="com.ibm.msg.client.ref.jar" />
<resource-root path="com.ibm.msg.client.wmq.common.jar" />
<resource-root path="com.ibm.msg.client.wmq.factories.jar" />
<resource-root path="com.ibm.msg.client.wmq.jar" />
<resource-root path="com.ibm.msg.client.wmq.v6.jar" />
<resource-root path="dhbcore.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.resource.api" />
<module name="javax.jms.api" />
<module name="javax.management.j2ee.api" />
</dependencies>
</module>
Note: In the main folder of this path I copied the mq-7.5.0.8.rar file too.
3) project-stages.yml:
resource-adapters:
resource-adapters:
mq:
archive: mq.rar
transaction-support: XATransaction
connection-definitions:
BSMConnectionFactoryHigh:
class-name: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl
jndi-name: jms/bsmConnectionFactoryHigh
config-properties:
hostName:
value: tqhr0712.sede.corp.sanpaoloimi.com
queueManager:
value: TQHR0712
port:
value: 1412
channel:
value: CH.BSMA.CONN
transportType:
value: CLIENT
admin-objects:
BSMSendQueueHigh:
class-name: com.ibm.mq.connector.outbound.MQQueueProxy
jndi-name: jms/bsmSendQueueHigh
config-properties:
baseQueueName:
value: QLOCAL.DATAGRAM.WUO.UOS4APPO9
baseQueueManagerName:
value: TQHR0712
deployment:
com.ibm.mq:mq.rar:
Then, when I run the project I get this error:
2018-02-08 10:33:54 INFO <org.jboss.as.server.deployment> <MSC service thread 1-7> WFLYSRV0028: Stopped deployment mq.rar (runtime-name: mq.rar) in 72ms
2018-02-08 10:33:54 INFO <org.jboss.as.controller> <main> WFLYCTL0183: Service status report
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.resourceadapters-subsystem (missing) dependents: [service jboss.deployment.unit."mq.rar".CONFIGURE_MODULE]
Someone would be kind to help to fix this problem?
Thank a lot.
I'm glad to tell you that I found how to make the Wildfly Swarm and IBM websphere mq resource adapter integration with success.
These are the steps to follow:
1) Get the wmq.jmsra.rar from IBM (version 8.x)
2) Creating the artifacts for this file like this:
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>8.0.0.7</version>
<type>rar</type>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>8.0.0.7</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
3) src/main/resources:
a) Create the folder modules.
b) Inside modules folder create com/ibm/mq/main.
c) Inside the main folder copy the resource adapter (the .rar file) and
rename it as mq.rar.
d) Inside main folder create the file module.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:2.0" name="com.ibm.mq">
<resources>
<resource-root path="." />
<resource-root path="com.ibm.mq.connector.jar" />
<resource-root path="com.ibm.mq.headers.jar" />
<resource-root path="com.ibm.mq.jar" />
<resource-root path="com.ibm.mq.jmqi.jar" />
<resource-root path="com.ibm.mq.pcf.jar" />
<resource-root path="com.ibm.mq.jmqi.local.jar" />
<resource-root path="com.ibm.mqjms.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.resource.api" />
<module name="javax.jms.api" />
<module name="javax.management.j2ee.api" />
</dependencies>
</module>
4) project-stages.yml:
swarm:
jca:
archive-validation:
enabled: false
fail-on-warn: false
resource-adapters:
resource-adapters:
mq:
archive: mq.rar
transaction-support: XATransaction
connection-definitions:
ReinoltroConnectionFactory:
class-name: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl
jndi-name: jms/testConnectionFactory
recovery-username:
recovery-password:
tracking: false
pool-name: MQCONNF
config-properties:
hostName:
value:
queueManager:
value:
port:
value:
channel:
value:
transportType:
value: CLIENT
admin-objects:
testQueue:
class-name: com.ibm.mq.connector.outbound.MQQueueProxy
jndi-name: jms/testQueue
pool-name: MQQUEUENAME
config-properties:
baseQueueName:
value:
baseQueueManagerName:
value:
deployment:
com.ibm:mq.rar:
5) Java code (send message using JMS 2)
#Stateless
#TransactionManagement(TransactionManagementType.CONTAINER)
public class RichiesteServiceImpl {
....
#Inject
#JMSConnectionFactory("java:/jms/reinoltroConnectionFactory")
JMSContext jmsContext;
#Resource(mappedName = "java:/jms/reinoltroBDQueue")
Queue testQueue;
.....
public boolean sendMessage() {
boolean esitoReinoltro = false;
try {
jmsContext.createProducer().send(reinoltroQueue, "Messaggio di prova" );
esitoReinoltro = true;
return esitoReinoltro;
}
catch(Exception e) {
throw new ServiceException(e);
}
}
}
and the job is done.
Here is my Nlog.Config code.
<nlog>
<variable name="logFilePath" value="C:\NLog\IDG-${shortdate}.log" />
<targets>
<target name="logfile"
xsi:type="File"
fileName="${logFilePath}"
layout="${longdate} LEVEL=${level:upperCase=true}: ${message}"
keepFileOpen="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="logfile" />
<logger name="*" minlevel="Warn" writeTo="file"/>
</rules>
</nlog>
and am defining this in my class
private static Logger logger = LogManager.GetCurrentClassLogger();
and then I'm logging the error as:
catch (Exception ex)
{
logger.Error(ex.Message,"test");
}
Can anyone please suggest me if there is any better way to do this, I don't see the file logging in the destined folder.
It seems that you may not be referencing the config section correctly. Try changing your main config file to something like this and remove the Nlog.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="logFilePath" value="C:\temp\output.log" />
<targets>
<target name="logfile"
xsi:type="File"
fileName="${logFilePath}"
layout="${longdate} LEVEL=${level:upperCase=true}: ${message}"
keepFileOpen="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="logfile" />
<logger name="*" minlevel="Warn" writeTo="file"/>
</rules>
</nlog>
</configuration>
I am trying to use OGNL in my tile but it considers the expression as a string ( whatever I use it counts as a string).
How should I change it in a way to count the expression as name of a page not string.
I am using the following code to embed the jsp file name, when admin user is logged in it replace ROLE_ADMIN with the #com.... expression but does not load menuRole_Admin.jsp page. It just shows menuRole_Admin.jsp as a string on browser.
<put-attribute name="menu" expression="OGNL: 'menu' +
#com.myproject.controller.Default#getRole() + '.jsp'"/>
tile.xml
<tiles-definitions>
....
<definition name="register1" extends="baseLayout">
<put-attribute name="menu" expression="OGNL: 'menu' +
#com.myproject.controller.Default#getRole() + '.jsp'"/>
<put-attribute name="body" value="/body.jsp"/>
</definition>
......
basLayout.jsp
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s"%>
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%#taglib uri="/struts-dojo-tags" prefix="sx" %>
<html>
<head>
....
</head>
<body>
<div id="container">
<div id="banner">
<tiles:insertAttribute name="header" />
</div>
<div id="menu">
<tiles:insertAttribute name="menu"/>
</div>
<div id="content">
<tiles:insertAttribute name="body"/>
</div>
<div id="footer">
<tiles:insertAttribute name="footer" />
</div>
</div>
</body>
</html>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
..........
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-glassfish</artifactId>
<version>9.1.02.B04.p0</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-dojo-plugin</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-taglib</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>3.1.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
<dependency>
<groupId>com.kenai.nbpwr</groupId>
<artifactId>org-apache-commons-dbcp</artifactId>
<version>1.2.2-201002241055</version>
<type>nbm</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-parent</artifactId>
<version>3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc</artifactId>
<version>1.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>fmt</artifactId>
<version>1.1.2</version>
<type>tld</type>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles3-plugin</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-el</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-ognl</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>b10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.tiles.extras.complete.CompleteAutoloadTilesListener</listener-
class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/myProject-security.xml
/WEB-INF/login-service.xml
</param-value>
</context-param>
<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>
</filter-mapping>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns='http://www.springframework.org/schema/beans'
xmlns:context='http://www.springframework.org/schema/context'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd'>
<context:component-scan base-package='com.myProject'/>
<bean id='internalResourceResolver'
class='org.springframework.web.servlet.view.InternalResourceViewResolver'>
<property name='prefix' value='/Web Pages/'/>
<property name='suffix' value='.jsp'/>
</bean>
<bean class='org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'/>
<bean class='org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'/>
<bean id='placeholderConfig'
class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/>
</beans>
myproject-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns='http://www.springframework.org/schema/security'
xmlns:beans='http://www.springframework.org/schema/beans'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd'>
<beans:import resource='login-service.xml'/>
<http auto-config="true" access-denied-page="/notFound.jsp" use-expressions="true">
<intercept-url pattern="/search/view*" access="hasRole('ROLE_ADMIN')" />
<form-login login-page="/index"
authentication-failure-url="/index?error=1"
default-target-url="/default"/>
<remember-me/>
<logout logout-success-url="/index.jsp"/>
</http>
<authentication-manager>
...........
Quaternion commented : I just realized you have Struts2, Spring-MVC AND Struts 1 all included in the same project... that is pretty weird. –
Add / to the begining of your address and remove all the dependencies which include tile in their names except the followings.
<put-attribute name="menu" expression="OGNL: '/menu' +
#com.myproject.controller.Default#getRole() + '.jsp'"/>
dependencies
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles3-plugin</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-el</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-ognl</artifactId>
<version>3.0.1</version>
</dependency>
Tried my best but no success. Index action is loaded fine but when I navigate to test than error is generated. Not sure why this is happening.
Using struts2 = 2.3.4.1
Tomcat latest
Tiles = 3.0.0
Pom.xml
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<struts2.version>2.3.4.1</struts2.version>
<slf4j.version>1.6.6</slf4j.version>
<tiles.version>3.0.0</tiles.version>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!--Start Slf4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--End Slf4j-->
<!--Start Struts2-->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<!--End Struts2-->
<!-- Start Tiles dependencies -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-ognl</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-freemarker</artifactId>
<version>3.0.0</version>
</dependency>
<!-- End Tiles dependencies -->
</dependencies>
struts.xml
<package name="default" namespace="/" extends="tiles-default">
<result-types>
<result-type name="tiles" default="true" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types>
<default-action-ref name="index"/>
<action name="index" class="com.myapp.tiles.action.Test">
<result type="tiles">/welcome.tiles</result>
</action>
<action name="test" class="com.myapp.tiles.action.Test">
<result type="tiles">test</result>
</action>
<action name="/**" class="com.myapp.tiles.action.Test">
<result>{1}</result>
</action>
</package>
Tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions >
<definition name="mainlayout" template="/templates/mainlayout.jsp">
<put-attribute name="meta" value="/templates/main/meta.jsp"/>
<put-attribute name="title" value=""/>
<put-attribute name="header" value="/templates/main/header.jsp"/>
<put-attribute name="search" value="/templates/main/search.jsp"/>
<put-attribute name="navigation" value="/templates/main/navigation.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="/templates/main/footer.jsp"/>
</definition>
<definition name="/welcome.tiles" extends="mainlayout">
<put-attribute name="title" value="Welcome To Person Management System"/>
<put-attribute name="body" value="/index.jsp"/>
</definition>
<definition name="test" extends="mainlayout">
<put-attribute name="title" expression="OGNL:title" />
<put-attribute name="body" value="/index.jsp"/>
</definition>
<definition name="WILDCARD:package/*" extends="mainlayout">
<put-attribute name="title" value="{1}" type="string"/>
<put-attribute name="body" value="/test.jsp"/>
</definition>
</tiles-definitions>
ERROR
Nov 17, 2012 8:28:51 AM org.apache.catalina.core.ApplicationContext log
java.lang.NoSuchMethodError: org.apache.tiles.access.TilesAccess.getContainer(Ljava/lang/Object;)Lorg/apache/tiles/TilesContainer;
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:100)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Project structure
First check your lib for duplicate or conflicting jars. As you are using maven try use plugin to check duplicate dependencies.
Second give Tiles 2.x.x a try. I never integrated Struts 2 and Tiles but met several No Class found exception with Spring 3.x and Tiles 3