my dog learned polymorphism*
The moose likes Struts and the fly likes symbol:method setBookList((nulltype)) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "symbol:method setBookList((nulltype))" Watch "symbol:method setBookList((nulltype))" New topic
Author

symbol:method setBookList((nulltype))

yuqing ma
Greenhorn

Joined: Nov 10, 2004
Posts: 11
OrderAction.java
package edu.sjtu.ebookstore.action;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Arrays;
import java.text.DecimalFormat;
import edu.sjtu.ebookstore.util.SelectedBook;
import edu.sjtu.ebookstore.common.User;
import edu.sjtu.ebookstore.common.Constants;
import edu.sjtu.ebookstore.beans.Book;
import edu.sjtu.ebookstore.beans.Order;
/**
* order action
* <p>Title: ebookStore</p>
* <p>Description: ebookStore</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Shanghai Jiaotong University</p>
* @author Liu Fang
* @version 1.0
*/

public class OrderAction extends Action
{
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
{
HttpSession session = httpServletRequest.getSession();
if(!edu.sjtu.ebookstore.service.CheckLogin.getInstance().isLogin(session))
{
return actionMapping.findForward("notLogon");
}
OrderActionForm orderActionForm = (OrderActionForm)actionForm;
User user = (User)session.getAttribute(Constants.USER_KEY);
java.util.Collection c = user.getBookList();
java.util.Iterator iterator = c.iterator();
SelectedBook[] bookList = new SelectedBook[c.size()];
for(int n=0;iterator.hasNext();n++)
{
Book book = (Book)iterator.next();
bookList[n] = new SelectedBook(book.getISBNID(),book.getName(),book.getAuthor(),book.getPrice());
}
orderActionForm.setBookList(bookList);
iterator = java.util.Arrays.asList(orderActionForm.getBookList()).iterator();
double totalPrice=0.0;
while(iterator.hasNext())
{
SelectedBook book = (SelectedBook)iterator.next();
Double price = Double.valueOf(book.getPrice());
totalPrice = totalPrice + price.doubleValue();
}
DecimalFormat format = new DecimalFormat("######0.00");
orderActionForm.setTotalPrice(format.format(totalPrice));
if(orderActionForm.getAction()!=null)
{
javax.sql.DataSource dataSource = (javax.sql.DataSource)this.servlet.getServletContext().getAttribute(edu.sjtu.ebookstore.common.Constants.DATASOURCE_KEY);
java.sql.Connection connection;
try
{
connection = dataSource.getConnection();
}
catch(Exception e)
{
return new ActionForward("/order.jsp");
}
SelectedBook[] booklist = orderActionForm.getBookList();
for(int n=0;n<booklist.length;n++)
{
Order order = new Order(user.getUserID(),booklist[n].getISBNID());
order.setConnection(connection);
try
{
order.saveOrder();
}
catch(java.sql.SQLException ex)
{
continue;
}
}
user.setBookList(null);
}
return new ActionForward("/order.jsp");
}
}

result rderAction.java:79:cannot find symbol
symbol:method setBookList((nulltype))
location:class edu.sjtu.ebookstore.common.User
user.setBookList(null)
^
User.java:
package edu.sjtu.ebookstore.common;

/**
* <p>Title: ebookStore</p>
* <p>Description: ebookStore</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Shanghai Jiaotong University</p>
* @author Liu Fang
* @version 1.0
*/
import edu.sjtu.ebookstore.beans.Book;
import java.util.ArrayList;
/**
* session class for managing user state
*/
public class User
{
private String userID;
private java.util.ArrayList bookList = new ArrayList();
/**
* constructor
* @param userID userID
*/
public User(String userID)
{
this.userID = userID;
}
public String getUserID()
{
return userID;
}
public void setUserID(String userID)
{
this.userID = userID;
}
public java.util.ArrayList getBookList()
{
return bookList;
}

/**
* Buy a new book.
* @param book
*/
public void addBook(Book book)
{
java.util.Iterator iterator = this.bookList.iterator();
while(iterator.hasNext())
{
Book b = (Book)iterator.next();
if(b.getISBNID().trim().compareToIgnoreCase(book.getISBNID().trim())==0)
{
return;
}
}
this.bookList.add(book);
}
/**
* remove a book from user's cart
* @param ISBN
*/
public void removeBook(String ISBN)
{
java.util.Iterator iterator = this.bookList.iterator();
while(iterator.hasNext())
{
Book b = (Book)iterator.next();
if(b.getISBNID().trim().compareToIgnoreCase(ISBN.trim())==0)
{
this.bookList.remove(b);
}
}
}
public void setBookList(java.util.ArrayList bookList)
{
this.bookList = bookList;
}
}
I don't correct it,please help me.thank you in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: symbol:method setBookList((nulltype))
 
Similar Threads
Generation of Random Number
complicate JSP tag : bodyContent
Logic:iterator issue in Struts 1.3.10
Inheritance - Mock Question & Explanation on Dan Chisholm's website.
Head First Design Patterns Composite Iterator