struts2 action编程
来源:互联网 发布:税友软件好用吗 编辑:程序博客网 时间:2024/05/29 11:14
struts2 action中属性与表单中提交的字段的关系如下,在使用时可以自动获取对应的值,无需手动获取。
package com.yht.web;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.yht.model.User;import com.yht.service.UserService;import com.yht.util.AppException;public class Login extends ActionSupport {private String name;private String password;private String massage;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getMassage() {return massage;}public void setMassage(String massage) {this.massage = massage;}@Overridepublic String execute() {String result="";try {int id = new UserService().login(name, password);User u = new User();u.setName(name);u.setId(id);u.setPassword(password);if(id!=0){massage = "登录成功";ActionContext context = ActionContext.getContext();Map<String,Object> session = context.getSession();session.put("userId", id);session.put("username", name);int role = new UserService().getUserRole(id);if(role==0)//普通编辑{result = "toEditor";}else if(role==1)//管理员{result = "toAdmin";}}else{result = "toLogin";massage = "登录失败";}} catch (AppException e) {result = "error";massage = "系统异常"+ e.getMessage();}return result;}}
在struts.xml中配置这个action
<package name="news" extends="struts-default"><!-- 接受登录信息,分发登录结果 --> <action name="login" class="com.yht.web.Login"> <result name="toEditor" type="redirectAction">toEditor</result> <result name="toAdmin" type="redirectAction">toAdmin</result> <result name="toLogin" type="dispatcher">/login.jsp</result> </action> </package>
0 0
- struts2 action编程
- Struts2 Action
- struts2 action
- Struts2---->action
- struts2------------action
- Struts2 Action
- Struts2 Action
- struts2-action
- Struts2-Action
- Struts2 Action
- struts2 action
- Struts2---Action
- Struts2-Action
- Struts2-Action
- Struts2-Action
- struts2 action
- Struts2-Action
- struts2--Action
- android开发笔记:常用权限说明
- 对linux平台远程升级的一些构想
- 单一设计模式
- Storyboard的基础知识-界面管理、多View切换、View间数据传递
- 用js模拟鼠标点击事件(事件触发)
- struts2 action编程
- c/c++经典面试试题及标准答案
- 腾讯安卓开发两面题目(2014)
- c++11标准中的lambda
- 《Linux 内核设计与实现》(LKD)第三版译者序
- oracle存储过程创建表权限不足解决方法
- ORACLE批量更新四种方法比较
- 对RTEMS移植剪裁的一些想法(闲聊)
- 蓝桥杯——基础训练之某天星期几