Struts2 jsp页面和Action之间的传值方式
来源:互联网 发布:淘宝店关注链接 编辑:程序博客网 时间:2024/04/23 22:34
Action向jsp传值
首先要在Action中声明所有要传向jsp页面的值的属性
然后生成get、set方法
UserAction.java
package cn.qdsoft.actions;import java.sql.Date;import java.util.List;import javax.annotation.Resource;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Namespace;import cn.qdsoft.BaseAction;import cn.qdsoft.dao.UserDAO;import cn.qdsoft.model.User;import cn.qdsoft.service.UserService;@Namespace("/user")public class UserAction extends BaseAction { // 必须声明为接口类型;important!!! @Resource private UserDAO userDAO; private List<User> userList; private User user; private Long id; private String login; private String name; private String passwd; private int type; private int status; private Date lastLogin; private Date gmtCreate; private Date gmtModified; private int createById; private int lastModifiedById; // 也在一个package中,package的名字不知道 // 父package 名字叫one @Action("list") public String list() { userList = userDAO.findAll(); return SUCCESS; } @Action("delete") public String delete() { System.out.println("user delete............"); Long id = getId(); System.out.println(id); return LIST; } public List<User> getUserList() { return userList; } public void setUserList(List<User> userList) { this.userList = userList; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPasswd() { return passwd; } public void setPasswd(String passwd) { this.passwd = passwd; } public int getType() { return type; } public void setType(int type) { this.type = type; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public Date getLastLogin() { return lastLogin; } public void setLastLogin(Date lastLogin) { this.lastLogin = lastLogin; } public Date getGmtCreate() { return gmtCreate; } public void setGmtCreate(Date gmtCreate) { this.gmtCreate = gmtCreate; } public Date getGmtModified() { return gmtModified; } public void setGmtModified(Date gmtModified) { this.gmtModified = gmtModified; } public int getCreateById() { return createById; } public void setCreateById(int createById) { this.createById = createById; } public int getLastModifiedById() { return lastModifiedById; } public void setLastModifiedById(int lastModifiedById) { this.lastModifiedById = lastModifiedById; }}
如果在User.java中已有了一下代码
private Long id; private String login; private String name; private String passwd; private int type; private int status; private Date lastLogin; private Date gmtCreate; private Date gmtModified; private int createById; private int lastModifiedById;
以及get、set方法就不需要在action中写了,只需要定义private User user;以及user的get、set
list.jsp
<%@ page pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <table class='table table-bordered table-hover table-striped'> <thead> <tr> <th>序号</th> <th>登录名</th> <th>真实姓名邮件</th> <th>密码</th> <th>类型</th> <th>状态</th> <th>最后登录时间</th> <th>创建时间</th> <th>最后修改时间</th> <th>创建人ID</th> <th>最后更新人ID</th> <th></th> <th></th> </tr> </thead> <tbody> <!-- getUserList() --> <s:iterator value="userList" status="s"> <tr> <td><s:property value="#s.index+1"/></td> <!-- getName() --> <td><s:property value="login" /></td> <td><s:property value="name" /></td> <td><s:property value="passwd" /></td> <td><s:property value="type" /></td> <td><s:property value="status" /></td> <td><s:property value="lastLogin" /></td> <td><s:property value="gmtCreate" /></td> <td><s:property value="gmtModified" /></td> <td><s:property value="createById" /></td> <td><s:property value="lastModifiedById" /></td> <!-- /user/edit.action?id=2&name=tom --> <td><s:a cssClass="ajax-link" action="edit"> <s:param name="id" value="id"/> 修改</s:a> </td> <td><s:a cssClass="ajax-link" action="delete"> <s:param name="id" value="id"/> 删除</s:a> </td> </tr> </s:iterator> </tbody></table></body></html>
value=”XXX” 是Action中的getXXX()方法
比如<td><s:property value="login" /></td>
就是getLogin()
jsp向 Action传值
统一name和value
struts2 <s:textfield> 标签与<s:property>标签value值设置为action属性值或者对象的属性值2.<s:textfield> 标签不能直接引用必须通过ognl表达式获取<s:textfield id="login" name="user.login" cssClass="form-control" value="%{account}" /><s:textfieldname="personAge" label="年龄" value="%{person.personAge}"/>
0 0
- Struts2 jsp页面和Action之间的传值方式
- Struts2--JSP页面和Action的交互
- struts2中jsp页面传值到action的两种方式
- 【 jsp】页面和Action 之间传递参数的两种方式
- Struts2 实现JSP页面之间的传值
- struts2中action向action之间传数据和action向jsp传数据理解
- Struts2中jsp页面和Action类的数据交互之OGNL和值栈
- struts2的action之间和action向jsp的参数传递
- struts2后台Action接收jsp页面的值
- Struts2 Action中传List值到jsp页面
- struts2 Action与jsp的传值
- jsp与action之间传参方式
- Struts2页面到action的三种传值方式
- Struts2页面到action的几种传值方式
- Struts2页面到action的三种传值方式
- Struts2页面到action的三种传值方式
- Struts2页面到action的三种传值方式
- Struts2三种传参方式(从jsp页面传到Action)
- 求解孪生素数--梅森素数
- 看群友转帖:编程就像要和女人同居 - 谈谈读后编程新领悟
- Android Studio Error:(2, 0) apply plugin: 'com.github.dcendents.android-maven'报错
- mssql2008 列转行语句
- 人邮出版社出的书 -- 从此不再光顾
- Struts2 jsp页面和Action之间的传值方式
- VMware克隆CentOS修改Linux MAC地址
- IOS端与Java端MD5加密方法
- 使用注释来显示PDT中的PHP代码助手 -- 郁闷用了6个月才发现这个功能
- python 关于文件的一些方法
- 在万网花了100大元买了域名iamsese.cn -- 亏了
- iamsese.cn 站点开发纪实 之 开篇1
- 动手制做自己的一张软盘大小的Linux 选项
- 如何安装MINIX 3 -- 这篇文档转自我在google上的博客