- Java code
package Action;import java.util.Iterator;import java.util.List;import Manager.BookManager;import admin.Book;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class ActionDemo01 extends ActionSupport { private BookManager bookmanager;//接收业务层 使用spring管理 private List<Book> list;//接收查询到的list private String bname;//接受的name @SuppressWarnings("unchecked") @Override public String execute() throws Exception { // TODO Auto-generated method stub Book book = new Book(); book.setBname(bname); list = bookmanager.booklist();// 这行报空指针 list是这个方法的值 return // hibernateTemplate.find("from Book"); bookmanager.addBook(book); Iterator it = list.iterator(); while (it.hasNext()) { System.out.println(it.next()); } return "ser"; } public BookManager getBookmanager() { return bookmanager; } public void setBookmanager(BookManager bookmanager) { this.bookmanager = bookmanager; } public List<Book> getList() { return list; } public void setList(List<Book> list) { this.list = list; } public String getBname() { return bname; } public void setBname(String bname) { this.bname = bname; }}
------解决方案--------------------------------------------------------
我猜有可能是manager的问题,在调试状态下看看bookmanager是否为null,如果是请检查拦截器的问题。