问题描述
源码:packagecom.intern.servlet;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importcom.intern.Page.Page;importcom.intern.entity.PracticeResultInfo;importcom.intern.entity.TeacherInfo;importcom.intern.jbdc.PracticeResultInfoDAO;importcom.sun.org.apache.regexp.internal.RESyntaxException;publicclassPracticeServletextendsHttpServlet{PracticeResultInfoDAOpraDAO=newPracticeResultInfoDAO();publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PracticeResultInfopra=newPracticeResultInfo();request.setCharacterEncoding("utf-8");Stringoper=request.getParameter("oper");if(oper.equals("getAll")){//实现查询所有学生数据List<PracticeResultInfo>data1=praDAO.getAll();//将数据放到request中,转给JSP显示request.setAttribute("data1",data1);//转发request.getRequestDispatcher("/pra_manager.jsp").forward(request,response);}if(oper.equals("getOne")){StringstrId=request.getParameter("id");intid=Integer.parseInt(strId);PracticeResultInfote=praDAO.getById(id);//将数据放到requet中,转给JSP显示request.setAttribute("te",te);//转发request.getRequestDispatcher("/pra_show.jsp").forward(request,response);}//添加用户信息if(oper.equals("add")){PracticeResultInfouserAd=newPracticeResultInfo();userAd.setStuId(Integer.getInteger(request.getParameter("stuId")));userAd.setStuName(request.getParameter("stuName"));userAd.setStuNo(request.getParameter("stuNo"));userAd.setStuClass(request.getParameter("stuClass"));userAd.setTeaName(request.getParameter("teaName"));userAd.setPrTitle(request.getParameter("praTitle"));userAd.setPrContent(request.getParameter("prContent"));userAd.setPrFile(request.getParameter("prFile"));request.setAttribute("userAd",userAd);if(praDAO.add(userAd)){request.setAttribute("msg","添加实习生记录成功!");}else{request.setAttribute("msg","添加实习生记录失败!");}request.getRequestDispatcher("/pra_add.jsp").forward(request,response);}//删除用户信息if(oper.equals("delete")){StringusId=request.getParameter("id");intid=Integer.parseInt(usId);if(praDAO.delete(id)){request.setAttribute("msg","删除实习生记录成功!");}else{request.setAttribute("msg","删除实习生记录失败!");}request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}//修改用户信息if(oper.equals("get")){StringusId=request.getParameter("id");intid=Integer.parseInt(usId);PracticeResultInfot=praDAO.getById(id);request.setAttribute("t",t);request.getRequestDispatcher("/pra_update.jsp").forward(request,response);}if(oper.equals("update")){pra.setStuId(Integer.parseInt(request.getParameter("stuId")));pra.setStuName(request.getParameter("stuName"));pra.setStuNo(request.getParameter("stuNo"));pra.setStuClass(request.getParameter("stuClass"));pra.setTeaName(request.getParameter("teaName"));pra.setPrTitle(request.getParameter("prTitle"));pra.setPrContent(request.getParameter("prContent"));pra.setPrFile(request.getParameter("prFile"));if(praDAO.update(pra)){request.setAttribute("msg","修改实习生记录成功!");request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}else{request.setAttribute("msg","修改实习生记录失败!");request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}}//分页//按页进行搜所if(oper.equals("getByPage")){//默认查询所有数据Stringsql="select*frompracticeResultinfoorderbyid";//定义数据查询集合List<PracticeResultInfo>allData=null;//获取查询的参数值//获取关键字的名称和值StringkeywordName=request.getParameter("keywordName");StringkeywordValue=request.getParameter("keywordValue");StringorderBy=request.getParameter("orderBy");//如果查询参数不为空,从新构建sql语句if(keywordName!=null&&keywordValue!=null){sql="select*frompracticeResultinfowhere"+keywordName+"like'%"+keywordValue+"%'";//确定排序规则if(orderBy.equals("0")){sql=sql+"orderbyid";}else{sql=sql+"orderby"+orderBy;}//将查询数据放到Session中保存request.getSession().setAttribute("sql",sql);}//判断Session中存在查询条件,进行分页if(request.getSession().getAttribute("sql")!=null){sql=(String)request.getSession().getAttribute("sql");}//SQL确定后进行分页查询allData=praDAO.getBySQL(sql);//判断是否含有页码信息StringcurrentPageStr=request.getParameter("pageCode");intcurrentPage=1;//如果有页码,则获取页码if(currentPageStr!=null){currentPage=Integer.parseInt(currentPageStr);}//创建Page对象进行分页Pagep=newPage(allData.size(),currentPage,10);//得到页面数据Listdata=praDAO.getByPage(p,allData);//将获得的当前页面数据保存到request中request.setAttribute("data",data);//将分页信息保存到request中request.setAttribute("page",p);//转向request.getRequestDispatcher("/pra_manager.jsp").forward(request,response);}}}错误提示:严重:Servlet.service()forservlet[PracticeServlet]incontextwithpath[/intern]threwexception[java.lang.NullPointerException]withrootcausejava.lang.NullPointerExceptionatorg.apache.jsp.pra_005fmanager_jsp._jspService(pra_005fmanager_jsp.java:124)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)atorg.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)atorg.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)atorg.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)atorg.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)atcom.intern.servlet.PracticeServlet.doPost(PracticeServlet.java:151)atcom.intern.servlet.PracticeServlet.doGet(PracticeServlet.java:24)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:621)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)atorg.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)atorg.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)atorg.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)atorg.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)atjava.lang.Thread.run(Thread.java:619)
解决方案
解决方案二:
你至少把空指针的那一行标注出来啊。!
解决方案三:
根据置顶帖,是不是得直接给你删了。你这像是来问问题的吗。。
解决方案四:
楼主打断点可以直接看看哪一行出错了,找到空指针位置,问题也就解决75%了。空指针也不是很难处理的问题,一般就是对象为空或没有初始化,检查下就是了。
解决方案五:
你打断点,自己DEBUG,光看,看不出来
解决方案六:
楼主啊!错误自己用很显眼的颜色弄出来啊!
解决方案七:
都是代码,看晕了,建议楼主下次要问时应该将出错点指出
解决方案八:
找到jsp对应的class/java,看124行代码
解决方案九:
atcom.intern.servlet.PracticeServlet.doPost(PracticeServlet.java:151)atcom.intern.servlet.PracticeServlet.doGet(PracticeServlet.java:24)错误给你标识出来了,你自己跟吧。。贴个代码也不贴行数,懒得数行数了