问题描述
<!--本页面负责查询arrival-book--><%@pagecontentType="text/html;charset=gbb2312"%><%@pagelanguage="java"pageEncoding="gb2312"%><%@pageimport="java.util.*"%><%@pageimport="java.sql.*"%><html><head>你好,本页面提供到库登记</head><body><formname="form"action=""method="post"><p>入库单编号<inputtype="text"name="id"value="2"><br><p>对应教材库的编号<inputtype="text"name="textbookId"value="1"><br><p>入库数量<inputtype="text"name="amount"value="9"><br><p>入库日期<inpttype="text"name="arrivalDate"value="12-23-2"><br><divalign="right"><inputtype="submit"name="submit"value="录入"/></div></form></body></html><%!intid,textbookId,amount,rs;%><%Stringids=request.getParameter("id");StringtextbookIds=request.getParameter("textbokId");Stringamounts=request.getParameter("amount");StringarrivalDate=request.getParameter("arrivalDate");//StringBufferstr=newStringBuffer();//下面进行数据类型装换if(ids!=null)id=Integer.parseInt(ids);if(textbookIds!=null)textbookId=Integer.parseInt(textbookIds);if(null!=amounts)amount=Integer.parseInt(amounts);//进行数据库的验证try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();}catch(Exceptione){System.out.println(e);}try{Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=Dian";Connectionconnection=DriverManager.getConnection(url,"chen","chen");Statementstmt=connection.createStatement();Stringsql="insertintoarrival_bookvalues("+id+","+textbookId+","+amount+",'"+arrivalDate+"');";if(id!=0)rs=stmt.executeUpdate(sql);if(0!=rs){//NewlocationtoberedirectedStringsite=newString("addsuccess.jsp");response.setStatus(response.SC_MOVED_PERMANENTLY);//实现页面重定向response.setHeader("location",site);}else{response.sendRedirect("add1.jsp");//str.append("添加失败");}}catch(Exceptione){System.out.println("2222222");}%>严重:Errorprocessingrequestjava.lang.NullPointerExceptionatorg.apache.catalina.connector.OutputBuffer.realWriteChars(OutputBuffer.java:457)atorg.apache.tomcat.util.buf.CharChunk.flushBuffer(CharChunk.java:393)atorg.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:275)atorg.apache.catalina.connector.Response.finishResponse(Response.java:453)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:578)atorg.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)atorg.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)atorg.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)atorg.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)atorg.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)atorg.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)atjava.lang.Thread.run(Thread.java:744)[color=#FF0000][/color]
解决方案
解决方案二:
Stringsite=newString("addsuccess.jsp");response.setStatus(response.SC_MOVED_PERMANENTLY);//实现页面重定向response.setHeader("location",site);改成response.sendRedirect("addsuccess.jsp");试试