<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <filter> <filter-name>strutsFilter</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>strutsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
@ParentPackage("basePackage") //指定父包java
@Namespace("/user") //指定命名空间web
@Results( { @Result(name = "success", location = "/main. jsp ")spring
@Result(name = "error", location = "/error.jsp") }) 全局的实现跳转的页面apache
@Action("userAction") //指定action的访问url 浏览器
例如:java代码注解缓存
1 package com.oracle.soccerleague.action; …… 22 @Namespace(value="/admin") 23 @ParentPackage(value="struts-default") 24 @Action(value="AddLeague") 25 @Results({ 26 @Result(name="success", location="/admin/AddLeagueSucc.jsp"), 27 @Result(name="input", location="/admin/AddLeague.jsp") 28 }) 29 public class AddLeagueAction extends ActionSupport { 30 private int year; 31 private String season; 32 private String title; …… 100 }
对应的struts.xml配置文件oracle
以上注解与如下struts.xml配置做用相同: 6 <struts> 7 <package name="admin" namespace="/admin" extends="struts-default"> 8 <action name="AddLeague" 9 class="com.oracle.soccerleague.action.AddLeagueAction"> 10 <result name="success">/admin/AddLeagueSucc.jsp</result> 11 <result name="input">/admin/AddLeague.jsp</result> 12 </action> 13 </package> 14 </struts>
<!-- 指定由spring负责action对象的建立 -->app
<constant name="struts.objectFactory" value="spring" />jsp
<!-- 全部匹配*.action的请求都由struts2处理,能够扩展 -->编码
<constant name="struts.action.extension" value="action" />
<!-- 是否启用开发模式,上线时通常不须要开启,开发时获取更多的日志信息 -->
<constant name="struts.devMode" value="true" />
<!-- struts配置文件改动后,是否从新加载 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 设置浏览器是否缓存静态内容 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<!-- 每次HTTP请求系统都从新加载资源文件,有助于开发 -->
<constant name="struts.i18n.reload" value="true" />
<!-- 文件上传最大值 -->
<constant name="struts.multipart.maxSize" value="104857600" />
<!-- 让struts2支持动态方法调用,在调用时使用userAction !login .action方式进行调用 -->
<!-- Action名称中是否仍是用斜线 -->
<constant name="struts.enable.SlashesInActionNames" value="false" />
<!-- 容许标签中使用表达式语法 -->
<constant name="struts.tag.altSyntax" value="true" />
<!-- 对于WebLogic,Orion,OC4J此属性应该设置成true -->
<constant name="struts.dispatcher.parametersWorkaround" value="false" />