Strut2中action方法匹配、通配符的使用放安抚
来源:互联网 发布:mac定妆喷雾怎么用 编辑:程序博客网 时间:2024/05/01 15:58
Action动态方法调用DMI,struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/user">
<action name="user" class="com.cn.user.action.UserAction">
<result>/user_add_success.jsp</result>
<result name="delete">/user_delete_success.jsp</result>
</action>
</package>
</struts>
Index.jsp页面调用:
<a href="<%=basePath %>/user/user!add">添加用户</a><br />
<a href="<%=basePath %>/user/user!delete">删除用户</a><br />
UserAction的内容:
package com.cn.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
public String add() {
return "success";
}
public String delete(){
return "delete";
}
}
使用通配符
Strtus.xml文件的配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="actions" extends="struts-default" namespace="/actions">
<action name="Student*" class="com.cn.action.StudentAction" method="{1}">
<result>/Student{1}_success.jsp</result>
</action>
<action name="*_*" class="com.cn.action.{1}Action" method="{2}">
<result>/{1}_{2}_success.jsp</result>
</action>
</package>
</struts>
Action的内容:
public class StudentAction extends ActionSupport {
public String add() {
return SUCCESS;
}
public String delete() {
return SUCCESS;
}
}
public class TeacherAction extends ActionSupport {
public String add() {
return SUCCESS;
}
public String delete() {
return SUCCESS;
}
}
Index.jsp页面的内容:
使用通配符,将配置量降到最低<br />
但是 一定要遵守"约定优于配置"的原则,在实际项目开发中由于多人开发,为了使代码通俗易懂一般情况下很少使用通配符。<br />
<a href="<%=basePath%>/actions/Studentadd">添加学生</a>
<a href="<%=basePath%>/actions/Studentdelete">删除学生</a><br />
//上面配置文件里({1}_{2}_success.jsp)在这里即Teacher_add_success.jsp
<a href="<%=context%>/actions/Teacher_add">添加老师</a>
<a href="<%=context%>/actions/Teacher_delete">删除老师</a>
<a href="<%=context%>/actions/Course_add">添加课程</a>
<a href="<%=context%>/actions/Course_delete">删除课程</a>
</body>
</html>
- Strut2中action方法匹配、通配符的使用放安抚
- Strut2中action方法匹配、通配符的使用方法
- strut2 通配符的使用
- struts2的action方法匹配以及通配符的使用
- struts2的action方法匹配以及通配符的使用
- struts2的action方法匹配以及通配符的使用
- strut2中通配符实现不同方法的调用
- Action中通配符的使用
- Action中匹配多个方法使用(通配符*) <action name="role_*" class="roleAction" method="{1}">
- struts2中动态方法调用和使用通配符定义Action
- Struts2中Action有很多方法 使用通配符
- 【struts2】action中使用通配符
- 【struts2】action中使用通配符
- strut2 使用通配符配置的好处和注意是事项
- 八、动态方法的调用和使用通配符定义action
- struts中关于action的通配符的使用
- 2、struts2开发action 的三种方法以及通配符、路径匹配原则、常量
- strut2 optiontransferselect 标签使用如何在action中获取list和doublelist里面的数据
- Codeforces Round #149 (Div. 2) Dispute (队列+容器模拟)
- 【java之路】我的java之路
- Let the Balloon Rise
- 状态位
- tomcat
- Strut2中action方法匹配、通配符的使用放安抚
- 停止hadoop2.2.0时提示no namenode to stop
- Linux学习-shell利用正则表达式验证邮箱合法性
- 快速解密ABE方案理解
- 有关CSS3中的选择器(一)
- 菜鸟程序猿开发注意事项
- 219C - Color Stripe-模拟
- android中ImageView的内存问题
- zkw线段树