Struts2.x开发步骤
来源:互联网 发布:php html转markdown 编辑:程序博客网 时间:2024/06/15 23:18
struts 2 的开发步骤(具体的代码我就不写了,这里主要讲开发的步骤)
1.编写Javabean和DAO类,在strut1中,Javabean需要继承于struts1 api中的ActionForm类。
struts2没有此要求。
struts2 也没有formbean,它有另外一套从表单往action传递数据的方式。
如:action文件里有一个private User user这个变量,而前端的表单要通过(假设user里面有两个属性,分别为:userName和pwd)代码:"checkLogin"(action中的name),user.userName,user.pwd 这样就可以把前端属性的数据传到action中去!
2.编写Action
在struts1, action必须继承于struts1 api 中Action
struts2,没有继承类或实现接口的要求,随便写一个类,都可以做struts2 的action
action中的处理请求的方法的签名是有要求
public String execute()
这个方法要写(return null 的意思也是不跳转页面)
在action中获取response对象
ServletActionContext.getResponse();
2.配置Action(参数是举例子,不一定是一样的)
在struts.xml文件中配置Action
package用组织action
<package name="user" namespace="/" extends="struts-default">
(package 中的user相当于一个标志意义,比如说这个package是用户模块,下一个package可能name就不同了,他可能表示其他的意思)
(namespace="/",这个作用如:我要调用下面的action的话,就必须要这么干/action)
(extends="struts-default"这个包里面包含了很多struts2.0的功能,不然下面的action就会没有功能)
<action name="checklogin" class="myuser.CheckLoginAction" method="execute"></action>
(这个action配置和Struts1.0有点类似,这个method="execute"方法其实就在CheckLoginAction中,只是我没有写出来而已)
3.配置web.xml文件:
//刚刚下载下来的web.xml有很多注解,我们把它删掉,保留下面的代码即可!
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
阅读全文
0 0
- Struts2.x开发步骤
- 【struts2】struts2的开发步骤
- [Struts]Struts2开发步骤
- Struts2框架开发步骤
- Struts2应用开发步骤
- Struts2开发步骤
- struts2开发步骤
- struts2开发步骤详情
- Struts2入门开发步骤
- Struts2开发步骤
- Struts2开发步骤
- Struts2的开发步骤
- Struts2开发步骤
- struts2开发步骤
- Struts2开发步骤
- Struts2开发步骤
- Struts2开发步骤
- Struts2应用开发步骤
- Mobx使用详解
- 继承
- tftp transfer timed out
- 软件开发流程
- Tensorflow在Anaconda环境下安装以及一些问题【转】
- Struts2.x开发步骤
- 面试问题:进程与线程的区别和联系
- (60)StringBuffer:特点、存储、删除、获取、修改
- Qt中的JSON支持
- day01之合并两个有序链表+实现1+2+3...+n要求不能使用乘除法循环条件判断等
- redis的持久化
- session技术
- centos中/etc/issue的字符格式
- Unity简单的声音切换渐变实现