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

寻jsp高手
出错信息
java.lang.NullPointerException
com.control.searchbookservlet.doPost(searchbookservlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

servlet:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.model.bookbean;
import com.model.bookDAO;

public class searchbookservlet extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html;charset=gb2312");
bookDAO dao=new bookDAO();
bookbean book=new bookbean();
try
{
String w =request.getParameter("bookid");
book=dao.searchbook(w);
if(book.getbookid()!=null)
{
RequestDispatcher view = request.getRequestDispatcher("showbook.jsp");
view.forward(request,response);
}
else
{
RequestDispatcher view = request.getRequestDispatcher("error.jsp");
view.forward(request,response);
}
}
catch(Exception e){e.printStackTrace();}
request.setAttribute(book.getbookid(),book);
}
}

------解决方案--------------------
这是空指针啊 你加断点调试一下
------解决方案--------------------
String w =request.getParameter("bookid");
没取到值吗
注意下名字是不是对的检查下
------解决方案--------------------
你的book应该为空吧
------解决方案--------------------
探讨
现在页面没错误了,但是是空页面,请各位大神指教啊