博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts2中怎样动态指定执行方法
阅读量:4647 次
发布时间:2019-06-09

本文共 823 字,大约阅读时间需要 2 分钟。

struts.xml文件:

<struts>

    <constant name="struts.devMode" value="true" />

    <package name="user" extends="struts-default" namespace="/user">

       <!--第一种方法-->

        <action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">

            <result>/user_add_success.jsp</result>
        </action>
        <!--第二种方法-->
        <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
            <result>/user_add_success.jsp</result>
        </action>
    </package>

</struts>

jsp文件:

<body>

<a href="<%=context %>/user/userAdd">添加用户</a><br /><!--第一种方法-->
<a href="<%=context %>/user/user!add">添加用户</a><br /><!--第二种方法-->
</body>

总结:

            (1)Action执行的时候并不一定要执行execute方法,可以在配置文件中配置Action的时候用method=来指定执行哪个方法,

             (2)也可以在url地址中动态指定(动态方法调用DMI)(推荐)前者会产生太多的action,所以不推荐使用

                感觉比servlet要简单和方便许多,可以提高效率。但是地址问题还是经常出错。百度上使用绝对地址,尽量少使用相对地址。

转载于:https://www.cnblogs.com/ksxx/p/5358831.html

你可能感兴趣的文章
使用 IntraWeb (39) - THttpRequest、THttpReply
查看>>
ImageMagick还是GraphicsMagick?
查看>>
[BZOJ 4571][Scoi2016]美味(主席树)
查看>>
python网络-计算机网络基础(23)
查看>>
Mysql5.7.16安装过程
查看>>
Linux文件查找命令find用法整理(locate/find)
查看>>
20175333曹雅坤实验四《Android程序设计》实验报告
查看>>
max(min)-device-width和max(min)-width的区别
查看>>
geolocation/ 百度地图api Geolocation 定位当前城市信息
查看>>
JAVA基础
查看>>
ruby的optparse使用小记
查看>>
Helper Devise: could not find the `Warden::Proxy` instance on request environment
查看>>
javascript--识别判断浏览器
查看>>
python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
查看>>
SQL语句增加列、修改列类型、修改列、删除列
查看>>
DataTable相关
查看>>
c++中wstring 和 string的转换
查看>>
Linux的历史
查看>>
ArcGIS API For Silverlight使用在线地图的多种方法总结
查看>>
如何定义 Java 中的方法
查看>>