SSH学习--struts的action中BaseAction的作用
来源:互联网 发布:有淘宝店铺可以直播吗 编辑:程序博客网 时间:2024/05/16 06:20
通常struts中的action一般都是继承ActionSupport的
public void loginCheck() throws Exception {HttpServletResponse response = ServletActionContext.getResponse();response.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();try {out.println(userLogic.loginCheck(userDTO.getUserLoginName(), userDTO.getUserPwd()));} catch (Exception e) {e.printStackTrace();} finally {out.flush();out.close();}}
而发现有些项目中的则是继承BaseAction的
public void loginCheck() throws Exception {PrintWriter out = getWriter();try {accountLogic.getAllAccount();out.flush();} catch (Exception e) {e.printStackTrace();} finally {out.close();}}
ActionSupport是struts2自带的类, BaseAction是自己的一个封装
这是BaseAction中的内容:
可以看出BaseAction1也是继承自ActionSupport的,只是里面增加一些公用的属性和方法,例如获取httpRequest,又比如获取用户信息的方法,完全是自己封装的。public class BaseAction extends ActionSupport {private static final long serialVersionUID = 1L;PrintWriter getWriter() throws IOException {HttpServletResponse response = ServletActionContext.getResponse();response.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");return response.getWriter();}HttpSession getSession(){HttpServletRequest request = ServletActionContext.getRequest();return request.getSession();}}
这样做避免每个action甚至每个方法都要写这些,增加了代码的复用性。
0 0
- SSH学习--struts的action中BaseAction的作用
- struts拦截所有action的低级错误,继承BASEACTION导致报错
- 提取出Action公共的部分BaseAction
- struts.xml中action标签的学习
- struts的action中attribute属性是什么作用?
- Struts的配置文件struts-config.xml中action元素的parameter属性作用
- struts action-mapping中的input的作用
- struts中用BaseAction继承DispatchAction,方面spring中service的调用
- 页面输入的数据格式转换类:BaseAction(常用于Struts框架中)
- Struts中Action的种类
- struts 中 action 的重用
- struts中常用的action
- Struts中Action的配置
- struts-config.xml中配置action的input属性的作用
- 简单解释SSH框架中Action、Service、Dao、struts、Spring之间的关系
- 85-002-11 在web项目中对Action层进行公共方法的抽取放入到BaseAction中
- struts中constant的作用
- struts中 Actionsupport 的作用
- 月薪3万的程序员都避开了哪些坑
- viewDidLoad和initWithNibName的具体含义
- U盘装系统时 ,找不到本地磁盘
- iOS 将16数据转换成2进制字符串
- android文件上传
- SSH学习--struts的action中BaseAction的作用
- 视频框架 Vitamio 使用教程+部分心得 (三) 视频控制器MediaController + 部分中文API
- 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-17-Embedding Layers
- 【FastDev4Android框架开发】Android 数据缓存器ACache的详解和使用(四)
- HDU 3262 Seat taking up is tough
- E哥的Git教程(一)热身篇
- git版本1.7.6的问题
- 摘自<编写高质量代码:改善Java程序的151个建议>
- HDU 1398 Square Coins (母函数)