当前位置: 代码迷 >> Java Web开发 >> struts2为何会在jsp页面中得不到list的数据呢
  详细解决方案

struts2为何会在jsp页面中得不到list的数据呢

热度:8753   发布时间:2013-02-25 21:14:44.0
struts2为什么会在jsp页面中得不到list的数据呢
我的代码如下:
Book.java

package com.sevnce.bean;

import java.sql.Date;

public class Book {
private String name;
private String author;
private Date publishedDate;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}

public Date getPublishedDate() {
return publishedDate;
}
public void setPublishedDate(Date publishedDate) {
this.publishedDate = publishedDate;
}
}

BookAction.java

package com.sevnce.action;

import java.util.ArrayList;
import java.util.List;

import com.sevnce.bean.Book;

public class BookAction {
public String title;
public Book book;
public static List<Book> bookList = new ArrayList<Book>();



public static void setBookList(List<Book> bookList) {
BookAction.bookList = bookList;
}

public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Book getBook() {
return book;
}

public void setBook(Book book) {
this.book = book;
}
public String initAdd(){
System.out.println("initAdd-----------");
return "initAdd";
}

public String add(){
bookList.add(book);
title = "添加书籍成功!";
System.out.println("add-----------");
return "success";
}
public String list(){
System.out.println("list----------- =" +bookList.size());
return "list";
}
public String clear(){
bookList.clear();
title = "清空书籍列表成功!";
System.out.println("clear-----------");
return "list";
}
public static List<Book> getBookList() {
return bookList;
}
}
listBook.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">  
  <title><s:property value="title"/></title> 
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
table {border-collapse: collapse; border: 1px solid #000000; margin-top: 20px; }
th, td {border: 1px solid #000000; font-size: 12px; }
body {font-size: 12px; }
</style>
  </head>
  
  <body>
  <table>
  <tr>
  <td>书名</td>
  <td>作者</td>
  <td>出版日期</td>
  </tr>
  <s:iterator id="book" value="bookList">
  相关解决方案