日期:2014-05-20  浏览次数:20840 次

struts2的配置问题?
在学习java王者归来的时候,第16章的例子,怎么也运行部起来,我把代码贴上来,大家帮我看看。
Book.java代码如下:
package com.hc.struts2.bean;
import java.sql.*;
public class Book {
private String name;
private String author;
private Date publishedDate;

}
BookAction.java代码如下:
package com.hc.struts2.action;

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

import com.hc.struts2.bean.Book;
public class BookAction {
public static List<Book> booklist = new ArrayList<Book>();

private String title ;
private Book book;
public String initAdd()
{
return "initBook";
}

public String Add()
{
booklist.add(book);
title = "<br/><br/>添加书籍成功<br/><br/>";
return "list";
}

public String list()
{
booklist.add(book);
return "list";
}

public String clear()
{
booklist.clear();
title = "清空书籍列表成功";
return "list";
}
public List<Book> getBookList()
{
return booklist;
}

}

initAddBook.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/struts-tags" prefix="struts" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My jsp 'index.jsp' starting page</title>
</head>
<body>
<a href ="<struts:url action = "initAddBook"/>">添加书籍 </a>
<a href ="<struts:url action = "listBook"/>">书籍列表 </a>
<a href ="<struts:url action = "clearBook"/>">清空书籍列表 </a>

<struts:form action="addBook">
<struts:label value="添加书籍"></struts:label>
<struts:textfield name="book.name" label="书名" />
<struts:textfield name="book.author" label="作者" />
<struts:textfield name="book.publishedDate" label="出版日期" />

<struts:submit value="添加"></struts:submit>
</struts:form>>
</body>
</html>

listBook.jsp代码如下:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/struts-tags" prefix="struts" %>

<title><struts:property value="titile" escape="false" /></title>
<table>
  <tr>
  <th>书名</th>
  <th>作者</th>
  <th>出版日期</th>
  </tr>
  <struts:iterator id="book" value="booklist">
  <tr>
  <td>${book.name}</td>
  <td>${book.author}</td>
  <td>${book.publishedDate}</td>
  </tr>
  </struts:iterator>
</table>

struts.xml配置如下:
<!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">
  <global-results>
  <result name="login">/login.jsp</result>
  </global-results>
  <action name="loginPerson" class="com.hc.struts2.action.LoginAction">