Struts2 Tomcat的配置

时间:2023-03-09 09:20:00
Struts2 Tomcat的配置

1. 下载Struts2包,网站http://struts.apache.org/download.cgi#struts2315

2. 将struts-2.3.15-all.zip 包解压到本地

3. 拷贝必要的jar包到工程的WEB-INF\lib目录下

commons-io-2.0.1.jar

javassist-3.11.0.GA.jar

ognl-3.0.6.jar

commons-fileupload-1.3.jar

freemarker-2.3.19.jar

xwork-core-2.3.15.jar

struts2-core-2.3.15.jar

commons-lang3-3.1.jar (不拷贝会出现tomcat错误,

java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils)

commons-lang-2.4.jar

4. 配置web.xml文件,配置struts2 filter, 这个web.xml指的是自己web工程下WEB-INF\web.xml不是tomcat的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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>Struts Blank</display-name> <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.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>

5. struts.xml 文件,放在src目录下

<?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.custom.i18n.resources" value="mess" />
<constant name="struts.i18n.encoding" value="utf-8" />
</struts>

发布工程,struts2基本功能可以生效了