Struts2 1.动态方法调用(1.指定method2.感叹号方式3.通配符方式)2.隐藏后缀名(三种方式)

3 篇文章 0 订阅
<pre name="code" class="html">
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<!-- 多包但唯一 -->
<package name="default" namespace="/" extends="struts-default">
<!-- 友好页面 要三个通配符 -->
<default-action-ref name="index"></default-action-ref>
<action name="index">
<result>/jsp/error.jsp</result>
</action>

<!--1 指定metho方法   页面调用http://localhost:8080/HelloWorld/addAction.action-->
<action name="addAction" method="add" class="com.imooc.action.HelloWorldAction">
<result>/jsp/add.jsp</result>
</action>
<action name="updateAction" method="update" class="com.imooc.action.HelloWorldAction">
<result>/jsp/update.jsp</result>
</action>


<!--2感叹号方式要配置的文件 页面调用http://localhost:8080/HelloWorld/helloworld!add.action  不推荐-->
<action name="helloworld" class="com.imooc.action.HelloWorldAction">
<result>/jsp/result.jsp</result>
<result name="addAction">/jsp/add.jsp</result>
<result name="updateAction">/jsp/update.jsp</result>
</action>

<!-- 3动态调用(通配符)  页面调用http://localhost:8080/HelloWorld/HelloWorld_add_action.action-->
<!--  action name="*_*_*" method="{2}" class="com.imooc.{3}.{1}Action">(*_*_*)ye可调用默认action,两个通配符有冲突(*_*)
<result>/result.jsp</result>
<result name="add">/{2}.jsp</result>
<result name="updateAction">/{2}.jsp</result></action>
-->
<!-- 页面调用http://localhost:8080/HelloWorld/helloworld_add.action   推荐-->
<action name="helloworld_*" method="{1}" class="com.imooc.action.HelloWorldAction">
<result>/jsp/result.jsp</result>
<result name="addAction">/jsp/{1}.jsp</result>
<result name="updateAction">/jsp/{1}.jsp</result>
</action>

</package>
<!-- 隐藏后缀名 1.web.xml配置2.struts.xml配置3.struts.properties配置       优先级递减-->
<constant name="struts.action.extension" value="do,html,xml"></constant>
<!-- 感叹号方式要配置的文件 页面调用www.http://localhost/HellWorld/hellowodl-->
<constant name="struts.enable.DynamicMethodInvocation" value="flase"></constant>
</struts>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值