struts2配置
web.xml代码:下
<web-app 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">
<display-name>Struts Blank</display-name>
<!--定义Struts2的FilterDispatcher的Filter-->
<filter>
<!--定义核心Filter的名字-->
<filter-name>struts2</filter-name>
<!--定义核心Filter的实现类-->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!--FilterDispatcher用来初始化Struts2并且处理所有的Web请求-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
struts.xml代码:下
namespace="/namespace "> .jsp .jsp *.action
属性介绍:
(1)package name属性是packages的必填元素,它作为一个关键字被后边的包引用;
extends元素是可选的,它允许包扩展一个和多个前边定义的包
namespace:是控制相应package下的action的url地址,调用时http://localhost:8080//namespace/.action
(2) action
struts.xml文件中配置<action…>元素时,它的name、class、method属性都可支持通配符,例如:
/success.jsp
/error.jsp
如上,定义一系列请求URL是xx_.action模式的逻辑Action。method属性值为一个表达式{1},表示它的值是name属性值中第一个的值
—————————————————————————————————— *.action
当该action返回"login"时,会chain到*.action 两个action之间可以传参