struts2struts.xml配置文件

xiaoxiao2025-07-11  15

struts.xml 配置初阶

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <!-- package 分模块管理 name 自定义,唯一 namespace 命名空间,和url请求路径相关,当result为相对路径时生效 extends 必须直接或间接继承struts-default --> <package name="default" namespace="/a" extends="struts-default"> <!-- 配置action 配置url和处理类的方法进行映射 name为请求名称,相对于namespace值,故如下请求应为 /a/hello class 处理类的完全限定名称,如果不配置由默认类处理 method 指定处理请求的方法,默认为execute方法 --> <action name="hello" class="com.action.HelloAction" > <!-- result 结果集配置 name 结果集名称,和处理方法的返回值匹配,故可以自定义,默认为“success”, struts2提供了5个返回结果: Action.SUCCESS:执行成功,跳转到下一页面 Action.NONE:执行成功,不需要视图显示 Action.ERROR:执行失败,显示失败页面 Action.INPUT:要执行该Action要更多的输入条件 Action.LOGIN:要登录后才能执行 type指定响应结果的类型 dispatcher 默认值,转发 redirect 重定向 redirectAction 重定向到Action result 的值为跳转页面地址,/代表绝对路径,不加/代表相对namespace的相对路径 --> <result name="success">/index.jsp</result> </action> </package> </struts>

 


   2.struts.xml 配置进阶

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <!-- constant 配置--> <!-- 扩展名配置 请求时的扩展名要匹配value值之一 --> <!-- 在此处,要访问 hello, 则访问末尾应为 hello.w --> <constant name="struts.action.extension" value="w"></constant> <!-- 编码配置--> <constant name="struts.i18n.encoding" value="utf-8"></constant> <!-- 开发模式--> <constant name="struts.devMode" value="true"></constant> <!-- include 配置--> <!-- 此操作是导入 src/structs/configuration/system.xml 配置文件--> <include file="structs/configuration/system.xml"></include> <action name="hello" class="com.action.HelloAction" > <result name="success">/index.jsp</result> </action> </struts>

 

转载请注明原文地址: https://www.6miu.com/read-5032901.html

最新回复(0)