启动服务器时发生错误
SEVERE: Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.NoClassDefFoundError: org/apache/tiles/el/ELAttributeEvaluator
at org.apache.struts2.tiles.StrutsTilesContainerFactory.createELEvaluator(StrutsTilesContainerFactory.java:247)
at org.apache.struts2.tiles.StrutsTilesContainerFactory.createAttributeEvaluatorFactory(StrutsTilesContainerFactory.java:198)
at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:106)
at org.apache.tiles.startup.AbstractTilesInitializer.createContainer(AbstractTilesInitializer.java:124)
at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:70)
at org.apache.tiles.web.startup.AbstractTilesListener.contextInitialized(AbstractTilesListener.java:62)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.tiles.el.ELAttributeEvaluator
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
... 15 more
Nov 08, 2016 4:10:58 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 08, 2016 4:10:58 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/TilesStrutDemo] startup failed due to previous errors
Nov 08, 2016 4:10:58 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 08, 2016 4:10:58 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Nov 08, 2016 4:10:58 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3332 ms
项目的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>TilesStrutDemo</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<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>
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="login" class="com.action.login.LoginDemo">
<result name="success" type="tiles">/welcome.tiles</result>
<result name="error">Login.jsp</result>
</action>
<action name="customer" class="com.action.login.LoginDemo">
<result name="success" type="tiles">/customer.success.tiles</result>
</action>
</package>
</struts>
* 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="" />
<put-attribute name="header" value="/Header.jsp" />
<put-attribute name="menu" value="/Menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/Footer.jsp" />
</definition>
<definition name="/welcome.tiles" extends="baseLayout">
<put-attribute name="title" value="Welcome" />
<put-attribute name="body" value="/Welcome.jsp" />
</definition>
<definition name="/customer.tiles" extends="baseLayout">
<put-attribute name="title" value="Customer Form" />
<put-attribute name="body" value="/Customer.jsp" />
</definition>
<definition name="/customer.success.tiles" extends="baseLayout">
<put-attribute name="title" value="Customer Added" />
<put-attribute name="body" value="/SuccessCustomer.jsp" />
</definition>
</tiles-definitions>
引入了menu.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Menu.....
</body>
</html>
header.jsp中
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Header..........
</body>
</html>
BaseLayout.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td height="250"><tiles:insertAttribute name="menu" /></td>
<td width="350"><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="footer" />
</td>
</tr>
</table>
</body>
</html>
footer.jsp中
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Footer.............
</body>
</html>
insert.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="t" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:form action="login">
<s:textarea name="number" label="number"/>
<s:submit value="Click" name="Click"></s:submit>
</s:form>
<s:url action="customer">Customer</s:url>
</body>
</html>
* loginDemo.java用于按操作*
调用的操作package com.action.login;
import com.opensymphony.xwork2.ActionSupport;
public class LoginDemo extends ActionSupport{
private int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String login(){
if(num%2==0){
return SUCCESS;
}else{
return ERROR;
}
}
public String customer(){
return SUCCESS;
}
}
lib add jar
commons-beanutils-1.8.0.jar
commons-collections-3.2.2.jar
commons-digester-2.0.jar
commons-fileupload-1.3.2.jar
commons-io-2.2.jar
commons-logging-1.1.3.jar
freemarker-2.3.22.jar
ognl-3.0.19.jar
struts2-core-2.3.31.jar
struts2-tiles-plugin-2.3.31.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
xwork-core-2.3.31.jar
tiles-servlet-2.2.2.jar
slf4j-api-1.7.12.jar
tiles-compat-3.0.1.jar
tiles-ognl-2.2.2.jar
tiles-freemarker-2.2.2.jar
javassist-3.11.0.GA.jar
struts2-tiles3-plugin-2.3.31.jar
JDK1.8
Tomcat 1.8