以struts2.1.6为列
步骤一:到官网下载一个struts2.1.6-all.zip的开发包
步骤二:解压上面的压缩包,进入apps目录,这里提供了几个参考例子,选择struts2-blank-2.1.6。
步骤三:根据struts2-blank-2.1.6的配置进行我们自己struts2应用的配置。
- 要添加的类库
- 添加一个struts.xml配置文件
- 修改我们的web应用的web.xml文件,添加一个struts2的核心拦截器
要类库如下如下:
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.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="mess"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result>/index.jsp</result>
</action>
<action name="login" class="cn.yunfei.action.LoginAction">
<result name="input">/login.jsp</result>
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
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">
<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>
</web-app>
---------------------------以上的为关键步骤。下面的只是举例中的一些小细节。不解析-----------------------------------