struts 通配符的使用
使用通配符可以将配置量降到最低,十分方便
新建一个javaweb项目
在项目中加入Struts.xml( 选中项目右键MyEclipse-->project facets-->Struts2-->finish)
在src项目下新建一个包action

在action包中新建一个studentAction,新建一个teacherAction。都继承ActionSupport方法
studentAction.java代码如下
package action;
import com.opensymphony.xwork2.ActionSupport;
public class studentAction extends ActionSupport {
public String add(){
return SUCCESS;
}
}
teacherAction代码如下
package action;
import com.opensymphony.xwork2.ActionSupport;
public class teacherAction extends ActionSupport {
public String add(){
return SUCCESS;
}
}
然后配置struts.xml文件
<struts>
<constant name="struts.devMode" value="true"/>
<package name="default" extends="struts-default" namespace="/action">
<action name="student*" class="action.studentAction" method="{1}" >
<result>/student{1}.jsp</result> </action>
<action name="*_*" class="action.{1}Action" method="{2}" >
<result>/{1}_{2}success.jsp</result>
</action>
</package>
</struts>
在webroot文件夹下新建两个jsp
一个为studentadd.jsp
一个为teacher_addsuccess.jsp
然后将index.jsp加入两个链接
<a href="action/studentadd"> 添加 </a>
<a href="action/teacher_add"> 添加 </a>
最后运行


路径很容易出错,有时候可能是你的MyEclipse的缘故,所以可以重启一下开发工具
不对的地方欢迎指正,谢谢!
struts 通配符的使用的更多相关文章
- 使用struts通配符报错
报错截图如下: 主要原因是:对大小写敏感. struts.xml StudentAction.java jsp页面:(重点就是这里,锚里面需要特别注意,大小写应该与struts.xml里面的保持一致, ...
- Struts通配符映射
- struts通配符*的使用
<action name="user_*" class="com.wangcf.UserAction" method="{1}"> ...
- Struts基础详解
1.web.xml配置: <filter> <filter-name>Struts2</filter-name> <filter-class> org. ...
- 手打struts知识点
Struts2概论 1.MVC原理 MVC(Model-View-Controller),程序设计理念 视图不用多说,html.jsp等 控制器,中转站,分配各个组件应当做什么,接受参数并跳转其他处理 ...
- Struts2学习-struts.xml文件配置
学习框架过程中,一直对框架中的配置文件比较难理解,特搜集资料简要记录一下struts.xml文件遇到的问题. <?xml version="1.0" encoding=&qu ...
- struts----通配符设置
本次学习的内容是struts通配符配置: 具体内容为: 一.准备工作 1.新建Web工程 2.添加struts:右键点击工程名选择My Eclipse-->点击add struts..--> ...
- 【SSH】——Struts2中的动态方法调用(二)
当action中的方法有很多时,那应该怎么调用呢?上次我们提到的UserAction类中只有一个execute方法,如果我们需要增加用户的增删改查方法,如下: public class UserAct ...
- struts之动态方法调用使用通配符
一.DMI动态方法调用的其中一种改变form表单中action属性的方式已经讲过了.还有两种,一种是改变struts.xml配置文件中action标签中的method属性,来指定执行不同的方法处理不同 ...
随机推荐
- 24个经典的MySQL索引问题,你都遇到过哪些?
索引 1.什么是索引? 2.索引有哪些优缺点? 3.索引使用场景(重点) 4.索引有哪几种类型? 5.索引的数据结构(b树,hash) 6.索引的基本原理 7.索引算法有哪些? 8.索引设计的原则? ...
- logback-spring.xml配置
logback-spring.xml配置 <?xml version="1.0" encoding="UTF-8"?> <configurat ...
- 计算两点间的距离(hdu2001)
注意:在C语言中,double->lf,结果保留两位小数->0.2lf #include<stdio.h> #include<math.h> using names ...
- (STL初步)不定长数组:vector
STL是指C++的标准模板库.(存储着一些常用的算法和容器) vector是一个不定长数组.它把一些常用的操作”封装“在vector类型内部. 例如,a是一个vector.1对元素的操作有,可以用a. ...
- 环境篇:Zeppelin
环境篇:Zeppelin Zeppelin 是什么 Apache Zeppelin 是一个让交互式数据分析变得可行的基于网页的开源框架.Zeppelin提供了数据分析.数据可视化等功能. Zeppel ...
- 初识Mysql 外键
1.创建学生表(主表) CREATE TABLE `stu` ( `stunum` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT N ...
- Mysql数值类型,小数点后保留两个零
如有不足请帮忙留言区补充谢谢~ 一,数值类型保留小数点后两个0 在存入数据时,应客户需求数值类型,比如钱数,分数等等需要精确到小数点后几位. 800存入时显示为800.00 方法:在建表时直接定义此数 ...
- Golang源码学习:调度逻辑(三)工作线程的执行流程与调度循环
本文内容主要分为三部分: main goroutine 的调度运行 非 main goroutine 的退出流程 工作线程的执行流程与调度循环. main goroutine 的调度运行 runtim ...
- [Android应用开发] 05.广播和服务
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Java中的集合(十五) Iterator 和 ListIterator、Enumeration
Java中的集合(十五) Iterator 和 ListIterator.Enumeration 一.Iterator (一).简介 Iterator 是一个接口,它是集合的迭代器.集合可以通过Ite ...