日期:2014-05-19  浏览次数:20654 次

新人求助,简单问题送分帖
login.jsp

<form method="post" action="login">
<input type="submit" value="提交" />
=============================================
  <servlet-mapping>
  <servlet-name>LoginServlet</servlet-name>
  <url-pattern>/login</url-pattern>
  </servlet-mapping>
=============================================
BookDao.java

public List<TBook> selevtAllBook(){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<TBook> bookList = new ArrayList<TBook>();

conn = this.getConn();
pstmt = conn.prepareStatement("select * from book");
rs = pstmt.executeQuery();
while(rs.next()){
TBook book = new TBook();
book.setBookName(rs.getString("bookName"));
book.setIsbn(rs.getString("isbn"));
book.setAuthor(rs.getString("author"));
book.setPublisher(rs.getString("publisher"));
book.setBookPrice(rs.getFloat("bookPrice"));
book.setDiscount(rs.getDouble("discount"));
book.setBookID(rs.getInt("bookID"));
bookList.add(book);
}
return bookList;
}
=============================================
loginservlet.java
BookDao bookDao = new BookDao();
List<TBook> bookList = bookDao.selevtAllBook();

request.setAttribute("id", bookList.get(6));
request.setAttribute("bookList", bookList);
request.getRequestDispatcher("bookList.jsp").forward(request, response);

我该如何在bookList.jsp这个页面,或者是在booklistservlet中得到bookList中的那个bookID

我在bookListservlet中写request.getParameter("id")怎么不行啊,得到的是null;

------解决方案--------------------
bookListservlet中写request.getParameter("id")怎么不行啊,得到的是null;

那你需要 在 url后增加 &id=111
或者你页面中增加一个 hidden的元素赋值给它