<?xml version="1.0" encoding="UTF-8"?> 文档为xml格式 字符编码为UTF-8
<!DOCTYPE struts PUBLIC (DOCTYPE是文档类型标签)根节点struts
"-//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="false"></constant> 配置属性 详情见constant节点介绍
<constant name="struts.devMode" value="true"></constant>
<package name="default" extends="struts-default"> name属性为每个package的唯一标识,extends可以指定本package继承另外一个package的所有配置
<default-action-ref name="index"></default-action-ref> 当没有对应的action时,默认执行的action (name属性的值)
<global-results> 当没有对应的result 默认的result
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"></exception-mapping>
</global-exception-mappings>
global-exception-mappings用于异常处理的标签可以配置在Action中,也可以配置在<global-exception-mappings>,顾名思义就是全局异常,当然执行Action的时候发生异常时,如果在Action中没有捕获异常而是抛出异常的话,struts2会首先在正在执行的Action中查找<exception-mapping>,寻找对应的Exception进行处理,如果找不到,才会去<global-exception-mappings>去寻找对应的Exception处理,如果还是找不到的话,就只好抛出异常了。上面是捕获java.lang.Exception异常 返回error result
<action name="Login" class="action.LoginAction" method="login"> 定义action 以及执行的类和方法
<result>/loginResult.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>