Struts2使用OGNL表达式封装输入数据(直接封装Map类型)
来源:互联网 发布:ubuntu 编译安装lnmp 编辑:程序博客网 时间:2024/05/21 07:46
struts2使用OGNL表达式封装数据,不仅支持对象,而且还支持诸如List,Map的容器
User.java
package HelloWorld;
public class User ...{
private String username;
private String password;
private String[] books;
public String[] getBooks() ...{
return books;
}
public void setBooks(String[] books) ...{
this.books = books;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
public String getPassword() ...{
return password;
}
public void setPassword(String password) ...{
this.password = password;
}
}
public class User ...{
private String username;
private String password;
private String[] books;
public String[] getBooks() ...{
return books;
}
public void setBooks(String[] books) ...{
this.books = books;
}
public String getUsername() ...{
return username;
}
public void setUsername(String username) ...{
this.username = username;
}
public String getPassword() ...{
return password;
}
public void setPassword(String password) ...{
this.password = password;
}
}
LoginAction.java
package HelloWorld;
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
public class LoginAction implements Action...{
private String tip;
private Map<String,User> users;
public Map<String, User> getUsers() ...{
return users;
}
public void setUsers(Map<String, User> users) ...{
this.users = users;
}
public String execute() throws Exception...{
//用第一个user做逻辑判断
if(this.getUsers().get("one").getUsername().equals("admin")&&this.getUsers().get("one").getPassword().equals("1234"))...{
ActionContext.getContext().getSession().put("user", this.getUsers().get("one").getUsername());
BookService bs=new BookService();
this.getUsers().get("one").setBooks(bs.getBooks());
this.setTip("welcome welcome");
return SUCCESS;
}else...{
return ERROR;
}
}
public String getTip() ...{
return tip;
}
public void setTip(String tip) ...{
this.tip = tip;
}
}
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
public class LoginAction implements Action...{
private String tip;
private Map<String,User> users;
public Map<String, User> getUsers() ...{
return users;
}
public void setUsers(Map<String, User> users) ...{
this.users = users;
}
public String execute() throws Exception...{
//用第一个user做逻辑判断
if(this.getUsers().get("one").getUsername().equals("admin")&&this.getUsers().get("one").getPassword().equals("1234"))...{
ActionContext.getContext().getSession().put("user", this.getUsers().get("one").getUsername());
BookService bs=new BookService();
this.getUsers().get("one").setBooks(bs.getBooks());
this.setTip("welcome welcome");
return SUCCESS;
}else...{
return ERROR;
}
}
public String getTip() ...{
return tip;
}
public void setTip(String tip) ...{
this.tip = tip;
}
}
index.jsp
<%...@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%...@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title></title>
</head>
<body>
<s:form action="Login">
<s:textfield name="users['one'].username" key="username"></s:textfield>
<s:textfield name="users['one'].password" key="password"></s:textfield>
<s:textfield name="users['two'].username" key="username"></s:textfield>
<s:textfield name="users['two'].password" key="password"></s:textfield>
<s:submit value="login"></s:submit>
</s:form>
</body>
</html>
pageEncoding="gb2312"%>
<%...@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title></title>
</head>
<body>
<s:form action="Login">
<s:textfield name="users['one'].username" key="username"></s:textfield>
<s:textfield name="users['one'].password" key="password"></s:textfield>
<s:textfield name="users['two'].username" key="username"></s:textfield>
<s:textfield name="users['two'].password" key="password"></s:textfield>
<s:submit value="login"></s:submit>
</s:form>
</body>
</html>
上面使用users['one'].username直接将输入数据封装成Map容器中的两个对象
- Struts2使用OGNL表达式封装输入数据(直接封装Map类型)
- Struts2使用OGNL表达式封装输入数据
- Struts2属性驱动封装(了),需要使用ognl表达式
- Struts2框架(二)参数封装、OGNL表达式、拦截器详解
- Struts2 封装集合或Map的数据
- OGNL表达式 模型驱动封装数据 获取null的问题
- Struts2数据封装
- Struts2数据封装机制
- Struts2数据的封装
- Struts2 数据封装机制
- Struts2 数据封装机制
- Struts2数据封装
- Struts2数据封装
- Struts2之数据封装
- Struts2数据封装
- Struts2数据封装机制
- Struts2 OGNL表达式的使用
- struts2中使用OGNL表达式
- mxml的标签
- Linux 2.6.x平台下后门程序
- C#笔试题目
- 在RichEdit控件中加入“复制”“粘贴”等功能
- 精妙SQL语句收集
- Struts2使用OGNL表达式封装输入数据(直接封装Map类型)
- mxml介绍
- 走在设计的路上
- java生成Excel
- 面向接口编程理解(转摘)
- Excel VBA编程笔记
- 转 JavaMail发送中文邮件中主题乱码的解决方法
- 下定决心写博客
- 从全球范围来看,网上购物商品比例