问题描述
我写了一个曾删改查的servlet代码如下packagecom.qun520;importjava.io.IOException;importjava.sql.SQLException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.apache.commons.dbutils.QueryRunner;importorg.apache.commons.dbutils.handlers.BeanListHandler;publicclassAdminBlogServletextendsHttpServlet{privatestaticfinallongserialVersionUID=1676990929597369678L;publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringmethod=request.getParameter("method");if(method.equals("addBlog")){addBlog(request,response);}elseif(method.equals("deleteBlog")){deleteBlog(request,response);}elseif(method.equals("editBlog")){editBlog(request,response);}elseif(method.equals("selectBlog")){selectBlog(request,response);}elseif(method.equals("displayBlog")){displayBlog(request,response);}System.out.println("333333333333333333333");}publicvoidaddBlog(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding("UTF-8");//接收JSP页面传递过来的三个参数Stringtitle=request.getParameter("title");Stringcontent=request.getParameter("content");StringcategoryId=request.getParameter("categoryId");intresult=0;System.out.println("222222222222222222222222");try{Stringsql="insertintoblog(title,content,categoryId,time)values(?,?,?,now())";Stringstr[]={title,content,categoryId};QueryRunnerqr=DbHelp.getQueryRunner();result=qr.update(sql,str);}catch(SQLExceptione){e.printStackTrace();}Stringmessage="";if(result==1){message=("添加成功");}else{message=("添加失败");}request.setAttribute("message",message);request.getRequestDispatcher("/Result.jsp").forward(request,response);System.out.println(result);}publicvoiddeleteBlog(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringstr=request.getParameter("id");Stringsql="Deletefromblogwhereid="+str;QueryRunnerqr=DbHelp.getQueryRunner();try{qr.update(sql);}catch(SQLExceptione){e.printStackTrace();}request.getRequestDispatcher("/servlet/GetBlogServlet").forward(request,response);}publicvoideditBlog(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringid=request.getParameter("id");intresult=0;Stringsql="selectid,title,content,timefromblogwhereid="+id;QueryRunnerqr=DbHelp.getQueryRunner();Listlist;try{list=(List)qr.query(sql,newBeanListHandler(Blog.class));Blogblog=(Blog)list.get(0);request.setAttribute("blog",blog);request.getRequestDispatcher("/xiugai.jsp").forward(request,response);}catch(SQLExceptione){e.printStackTrace();}}publicvoidselectBlog(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//Stringid=request.getParameter("id");QueryRunnerqr=DbHelp.getQueryRunner();System.out.println("444444444444444444444");try{Stringsql="selectid,title,content,categoryId,timefromblogorderbyiddesc";//DButils核心类,生成对象时传递数据源对象Listlist=(List)qr.query(sql,newBeanListHandler(Blog.class));request.setAttribute("list",list);request.getRequestDispatcher("/displaybloglist.jsp").forward(request,response);}catch(SQLExceptione){e.printStackTrace();}}publicvoiddisplayBlog(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{System.out.println("6666666666666666666666666666");Stringid=request.getParameter("id");Stringsql="selectid,title,content,timefromblogwhereid="+id;QueryRunnerqr=DbHelp.getQueryRunner();try{Listlist=(List)qr.query(sql,newBeanListHandler(Blog.class));Blogblog=(Blog)list.get(0);request.setAttribute("blog",blog);request.getRequestDispatcher("/displayblog.jsp").forward(request,response);}catch(SQLExceptione){e.printStackTrace();}}}我想查看指定的一片文章在地址栏输入http://localhost:8080/blog/servlet/AdminBlogServlet?method=displayBlog?id=4(指定文章的编号)却显示一个大白板而且什么错也没报哪位高手帮我解决一下!
解决方案
解决方案二:
调试下就好