Struts2关于struts.xml文件配置说明

来源:互联网 发布:微商城 源码下载 编辑:程序博客网 时间:2024/05/19 03:28

struts.xml是Struts2的核心配置文件,里面定义了请求与映射的关系。

package说明:

package的功能是用来管理action,一般可以按照模块功能划分。

<package name="helloworld" namespace="/" extends="struts-default"><action name="helloWorldAction" class="cn.itcast.HelloWorld.HelloWorldAction"><result name="index">index.jsp</result></action></package>
name为包的名称,且值唯一。

extends实际是把package名称为struts-default包的功能继承过来。

namaspace说明:

1.如果namaspace为"/"

那么在请求URL时项目名称后面紧跟着action中name名称;

http://localhost:8080/项目名称/helloworld.action

2.如果namaspace为“/base”

那么在请求URL时项目名称后面紧跟着/baser然后是action;

http://localhosr:8080/项目名称/base/helloworld.action

  如果请求为http://localhosr:8080/项目名称/base/a/helloworld.action也可以请求到,查找规则为:

先查找/base/a下的helloworld.action

如果没有,再查找/base下的helloworld.action

3.在URL中加了几层命名空间,则在转向jsp页面时,jsp的路径也会加几个命名空间名字的路径:

/base/helloworld.action

/base/index.jsp

   在命名空间中有什么名称,在webroot下就应该建立什么样的文件夹。

____________________________________________________________________________________________

结果集说明:

步骤:

1.action类中方法必须返回一个字符串;

2.返回的字符串要和struts.xml文件中result标签的name属性一致

result两个重要的属性:

name:和action返回值对应    可以省略    默认值为success

type:   为结果集类型               可以省略    默认为转发

——————————————————————————————————————————————————————

include标签:

<struts><include file="struts-helloworld.xml"></include></struts>
在大型项目中可以确保人手一份xml文件,这样不会出现冲突问题
____________________________________________________________________________________________

关于strurt.xml和strut-default.xml的说明:

1.这两个配置文件都是在服务器启动的时候加载的;

2.这两个配置文件都是放在classpath根目录下;

struts.xml在src根目录下

struts-default.xml在struts核心包的根目录下

3.struts.xml供程序员使用

   struts-default.xml是运行在struts底层的xml文件

4.先加载struts-default.xml文件,再加载struts.xml文件

5.因为dtd一样,如果出现相同的元素,后者会覆盖前者。









0 0
原创粉丝点击