OGNL(对象图导航语言)基础了解

来源:互联网 发布:lgd官方淘宝店 编辑:程序博客网 时间:2024/06/05 12:20

代码如下:Book.java:

package bean;public class Book {private String name;private int price;private int bookid;public int getBookid() {return bookid;}public void setBookid(int bookid) {this.bookid = bookid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public Book(String name, int price, int bookid) {super();this.name = name;this.price = price;this.bookid = bookid;}}
ChaoAction.java:
package chao;import java.util.ArrayList;import java.util.List;import bean.Book;public class ChaoAction {private String name;private List<Book> books;public List<Book> getBooks() {return books;}public void setBooks(List<Book> books) {this.books = books;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String execute() {books=new ArrayList<Book>();books.add(new Book("javaweb1",34,1));books.add(new Book("javaweb2",322,2));books.add(new Book("javaweb3",67,3));name = "chao";return "list";}}
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><package name="chao" extends="struts-default"><action name="hello_*" class="chao.ChaoAction" method="{1}"><result name="list">/WEB-INF/page/message.jsp</result></action></package></struts>
message.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%><%@taglib uri="/struts-tags" prefix="s"%><!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><s:property value="name" />${name }<br /> =======================================<br /><!-- 访问books --><s:iterator value="books.{?#this.price>60}"><s:property value="name" /><s:property value="bookid" /><s:property value="price" /><br /></s:iterator></body></html>
index.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%><%@taglib uri="/struts-tags" prefix="s"%><%request.setAttribute("user", "chao");request.getSession().setAttribute("user", "chao1");%><!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>         <!-- 获得简单属性 --><s:property value="#request.user" /><br /><s:property value="#session.user" /><!-- list集合 --><s:set var="list" value="{'1','2','3'}" /><!-- s:iterator会把当前迭代的对象放在栈顶 --><s:iterator value="list"><s:property /><br /></s:iterator><!-- map集合 --><s:set var="maps" value="#{'key1':90,'key2':12,'key3':34}" /><s:iterator value="maps"><s:property /><br /></s:iterator><br /> =======================================<br />


0 0
原创粉丝点击