struts2笔记(续六)

OGNL:

查询struts2中的配置信息:

Struts2-core-2.1.6.jar-àorg.apache.struts2--àdefault.properties

 

对应的Action,OGNLActiion.java,对于其中的一些属性类,如userList,bookSet,orgMap都为作声明:

package com.oristand.actions;

 

import java.util.ArrayList;

import java.util.HashMap;

import java.util.HashSet;

import java.util.List;

import java.util.Map;

import java.util.Set;

 

import com.opensymphony.xwork2.ActionSupport;

 

public class ONGLAction extends ActionSupport {

    //private Cat cat;

    private User user;

    private String username;

    private String password;

   

    private List<User> userList = new ArrayList<User>();

    private Set<Book> bookSet = new HashSet<Book>();

    private Map<String,Org> orgMap = new HashMap<String,Org>();

   

   

    public ONGLAction() {

       userList.add(new User(20));

       userList.add(new User(21));

       userList.add(new User(22));

      

       bookSet.add(new Book("史记"));

       bookSet.add(new Book("春秋"));

       bookSet.add(new Book("战国"));

      

       orgMap.put("第一名", new Org("东方标准"));

       orgMap.put("第二名", new Org("尚学堂"));

       orgMap.put("第三名", new Org("传智播客"));

    }

    @Override

    public String execute() throws Exception {

       return SUCCESS;

    }

//  public Cat getCat() {

//     return cat;

//  }

//  public void setCat(Cat cat) {

//     this.cat = cat;

//  }

    public Set<Book> getBookSet() {

       return bookSet;

    }

    public Map<String, Org> getOrgMap() {

       return orgMap;

    }

    public String getPassword() {

       return password;

    }

    public User getUser() {

       return user;

    }

    public List<User> getUserList() {

       return userList;

    }

    public String getUsername() {

       return username;

    }

    public void setBookSet(Set<Book> bookSet) {

       this.bookSet = bookSet;

    }

    public void setOrgMap(Map<String, Org> orgMap) {

       this.orgMap = orgMap;

    }

    public void setPassword(String password) {

       this.password = password;

    }

    public void setUser(User user) {

       this.user = user;

    }

    public void setUserList(List<User> userList) {

       this.userList = userList;

    }

    public void setUsername(String username) {

       this.username = username;

    }

 

}

 

相应的ognl.jsp:

 

   from value stack: username is:<s:property value="username"/><br>

   from value stack: password is:<s:property value="password"/><br>

   from value stack: user.age is:<s:property value="user.age"/><br>

   from value stack: user.cat.friend.name is:<s:property value="user.cat.friend.name"/><br>

   from value stack: user.cat.friend.name's length is:<s:property value="user.cat.friend.name.length()"/><br>

    from value stack: user.cat.miaomiao() is:<s:property value="user.cat.miao()"/><br>

    <hr/>

    测试static属性,@com.oristand.actions.Sta@str is <s:property value="@com.oristand.actions.Sta@str"/><br/>

    测试static方法,@com.oristand.actions.Sta@s()is <s:property value="@com.oristand.actions.Sta@s()"/><br><br>

    <hr/>

    new com.oristand.actions.User(8)" is: <s:property value="new com.oristand.actions.User(8)"/><br><br>

    <hr/>

   访问userList: <s:property value="userList"/><br>

   访问userList中的第二个元素:<s:property value="userList[1]"/><br>

   usreList中的age属性再封装成一个list,userList.{age} is:<s:property value="userList.{age}"/><br

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值