标签:http io ar java strong sp 文件 on cti
这几天闲来无事,开始学习struts2这几天都将学习struts2技术。
1.下载struts2.2.1.jar。拷jar包,下载的struts2.zip解压,app\struts2-
blank.war\WEB-INF]\lib下的所有jar包
2.打开MyEclipse,创建一个web project,然后将几个必备jar包拷贝至WEB-INF/lib,几个必备jar包分别为:
commons-fileupload-1.2.1.jar,
commons-io-1.3.2.jar,
commons-lang-2.3.jar,
freemarker-2.3.16.jar,
javassist-3.7.ga.jar,
ognl-3.0.jar,
struts2-core-2.2.1.1.jar,
xwork-core-2.2.1.1.jar
3.修改web.xml文件,加载strtus2的核心filter,让核心filter过滤所用的用户请求。
web.xml文件修改如下:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>nima.jsp</welcome-file> //当有几个welcome-file时,按顺序寻找欢迎页面,当前面的欢迎页面找不到时,才会寻找后面的页面
</welcome-file-list>
<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>
4.在classes目录下增加一个strtus2的配置文件,struts.xml,开发时该文件放在src目录下,
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" namespace="/" extends="struts-default">
<global-results>
<result name="error">WEB-INF/page/error.jsp</result>
</global-results>
<action name="logins" class="com.gree.action.LoginAction">
<exception-mapping result="sql" exception="java.sql.SQLException"></exception-mapping>
<exception-mapping result="illegal" exception="java.lang.IllegalArgumentException"/>
<result type="plainText" name="nima">
<param name="location">WEB-INF/page/success.jsp</param>
<param name="charSet">utf-8 </param>
</result>
<result>WEB-INF/page/success.jsp</result>
<result name="sql">WEB-INF/page/sqlerror.jsp</result>
<result name="illegal">WEB-INF/page/illegalerror.jsp</result>
</action>
<action name="register" class="com.gree.action.RegisterAction">
<result>WEB-INF/page/success.jsp</result>
</action>
<action name="finduser" class="com.gree.action.FindUserAction">
<result name="success">WEB-INF/page/display.jsp</result>
</action>
<action name="*">
<result> WEB-INF/page/{1}.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
标签:http io ar java strong sp 文件 on cti
原文地址:http://www.cnblogs.com/binggu/p/4041435.html