配置Struts2项目

来源:互联网 发布:linux命令行编辑文件 编辑:程序博客网 时间:2024/05/21 01:44
    参看了官方strust2-blank.war包里面的jar包,以及配置文件。
    导入jar包
    

    新建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="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.multipart.maxSize" value="104857600"/><!-- 100M -->
<!--配置临时文件存放目录 -->
<constant name="struts.multipart.saveDir" value="/tmp"/>
<!-- 配置后缀, 可以使用无后缀,sdo -->
<constant name="struts.action.extension" value="action,sdo" />
<package name="default" namespace="/" extends="struts-default,json-default">
 
<default-action-ref name="index" />
 
<global-results>
<result name="error">/error.jsp</result>
</global-results>
 
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
</package>
 
<include file="mystruts.xml"/>
 
<!-- Add packages here -->
 
</struts>
    上面的文件引入了mystruts.xml,则
    新建mystruts.sml
<?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="admin" namespace="/admin" extends="default">
<!--用户管理-->
<action name="user" class="com.mckj.xzly.action.UserAction">
<result name="login_success">/WEB-INF/admin/index.jsp</result>
<result name="login_error">/login.jsp</result>
<result name="success">/index.jsp</result>
</action>
</package>
<!-- 前台页面路径的包名 -->
<package name="index" namespace="/index" extends="default">
<action name="index" class="com.mckj.xzly.action.IndexAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
    新建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">
<display-name></display-name>
 
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.mckj.xzly.util.MyStrutsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<error-page>
<error-code>404</error-code>
<location>/error/error404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/error500.jsp</location>
</error-page>
 
<security-constraint>
<web-resource-collection>
<web-resource-name>fortune</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint></auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>

注:此处可供下载demo项目,仅供学习参考 http://download.csdn.net/detail/ergouge/9100207








    
0 0
原创粉丝点击