我的代码如下:
Book.javapackage 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.javapackage 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">
<tr>
<td> <s:property value="#book.name"/></td>
<td>${book.author }</td>
<td>${book.publishedDate }</td>
</tr>
</s:iterator>
</table>
hhhhhhhhhhhhhhh
</body>
</html>页面这些是肯定正常的跳转了的,struts.xml里面的配置也没有任何问题,但是就是没有取得到iterator里面的值,麻烦各位大侠帮忙看看啊。
Book.javapackage 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.javapackage 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">
<tr>
<td> <s:property value="#book.name"/></td>
<td>${book.author }</td>
<td>${book.publishedDate }</td>
</tr>
</s:iterator>
</table>
hhhhhhhhhhhhhhh
</body>
</html>页面这些是肯定正常的跳转了的,struts.xml里面的配置也没有任何问题,但是就是没有取得到iterator里面的值,麻烦各位大侠帮忙看看啊。
解决方案 »
- properties文件中的数剧无法更改的问题
- struts2 标签 集合过滤的问题
- input type=file 过滤上传文件只允许xls格式的
- 关于struts2的一个Action重复执行多次的问题。
- EJB是基于哪些技术实现的?并说出SessionBean和EntityBean的区别,StatefulBean和StatelessBean的区别。
- 【SOS】Hibernate Tools 3.2的问题
- oracle.sql.BLOB字段存储图片的问题
- 论坛数据库的图片调用出现问题,什么原因?
- 用过jfreechart的高手来看看,感谢感谢
- MS access是不是不支持PreparedStatement方法?
- 中文传值出现乱码的问题
- js跳转问题?
会不会acton 中bookList就没有值?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="main" extends="struts-default" namespace="/mainPart">
<global-results>
<result name="login">/login.jsp</result>
</global-results>
<action name="loginPerson" class="com.sevnce.action.TestAction" method="login">
<result name="success">/welcome.jsp</result>
<result name="login">/login.jsp</result>
</action>
<action name="logoutPerson" class="com.sevnce.action.TestAction" method="logout">
<result name="success">/welcome.jsp</result>
<result name="logout">/login.jsp</result>
</action>
</package>
<package name="book" extends="struts-default">
<action name="*Action" class="com.sevnce.action.BookAction" method="{1}">
<result>/successBook.jsp</result>
<result name="{1}">/{1}Book.jsp</result>
<result name="list">/listBook.jsp</result>
</action> </package></struts>
配置文件如上,action的方法肯定是执行到了的。
有值的,我有list.size(),如果我添加了一个book的实例的话,会体现出来的。
可以执行的,但是我用<s:debug>看了一下里面的值是空的。是怎么回事呢?
还是不行啊。我用<s:debug>看了一下里面的值是空的
public List<Book> booklist = new ArrayList<Book>();
public String list() {
title = "BookList";
for(int i=0;i<bookList.size();i++){
System.out.println(bookList.get(i));
booklist.add(bookList.get(i));
}
return "list";
}
public List<Book> getBooklist() {
return booklist;
} public void setBooklist(List<Book> booklist) {
this.booklist = booklist;
}页面取值如下
[code=Jsp]
<s:iterator value="booklist" status="book">
<tr>
<td><s:property value="name" /></td>
<td><s:property value="author" /></td>
<td><s:property value="publishedDate" /></td>
</tr>
</s:iterator>
[/code]
List的值可以得到了,但是为什么title的值也会得不到呢?