BookDetailAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. package BookStore;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.Action;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import javax.servlet.ServletContext;
  9. import javax.sql.DataSource;
  10. import java.sql.Connection;
  11. import java.sql.Statement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.util.*;
  15. import javax.servlet.http.*;
  16. import org.apache.struts.action.DynaActionForm;
  17. import org.apache.struts.action.ActionMessage;
  18. import org.apache.struts.action.ActionMessages;
  19. public final class BookDetailAction extends Action{  
  20. public ActionForward execute(
  21. ActionMapping mapping,
  22. ActionForm form,
  23. HttpServletRequest request,  
  24. HttpServletResponse response) throws Exception {
  25.     DynaActionForm bookIdForm = (DynaActionForm) form;         
  26. Integer bookId = (Integer)bookIdForm.get("bookId");
  27.         HttpSession session = request.getSession();
  28. Book book = new Book();
  29.     ServletContext context = servlet.getServletContext();
  30. DataSource dataSource = 
  31. (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  32.         DB db = new DB(dataSource);
  33.         book = Book.GetDetail(db,bookId.intValue());
  34. session.setAttribute(Constants.BOOK_DETAIL_KEY,book);
  35. db.close();
  36.     return (mapping.findForward("toBookDetail"));
  37.   }
  38. }