package com.csms.action.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.csms.dao.InterImpl.Oder_inFactory;
import com.csms.dao.inter.Oder_inInter;
import com.csms.dao.model.Oder_in;public class Oder_inServlet extends HttpServlet { /**
* Constructor of the object.
*/
public Oder_inServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doDelete method of the servlet. <br>
*
* This method is called when a HTTP delete request is received.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doDelete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { // Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String opt=request.getParameter("opt");
if(opt.equals("update"))
{
try {
doupdate(request,response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
*
*/
public void doupdate(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
// String Oder_no=request.getParameter("oder_nos");
// System.out.println("oder_no:"+Oder_no);
// Oder_inFactory oder_infac=new Oder_inFactory();
// Oder_inInter oder_ininter=oder_infac.getOder_inImpl();
// Oder_in oder_in =new Oder_in();
// oder_in=oder_ininter.queryOder_in(Oder_no);
//
//// request.setAttribute("oder_in", oder_in);
// response.sendRedirect(request.getContextPath()+"stock/order2002.jsp");
request.getRequestDispatcher("/stock/order2002.jsp").forward(request, response);
return ;
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
debug 跟踪request.getRequestDispatcher("/stock/order2002.jsp").forward(request, response);时报
2012-6-21 18:23:07 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet Oder_inServlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.csms.action.servlet.Oder_inServlet.doupdate(Oder_inServlet.java:144)
at com.csms.action.servlet.Oder_inServlet.doPost(Oder_inServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.csms.dao.InterImpl.Oder_inFactory;
import com.csms.dao.inter.Oder_inInter;
import com.csms.dao.model.Oder_in;public class Oder_inServlet extends HttpServlet { /**
* Constructor of the object.
*/
public Oder_inServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doDelete method of the servlet. <br>
*
* This method is called when a HTTP delete request is received.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doDelete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { // Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String opt=request.getParameter("opt");
if(opt.equals("update"))
{
try {
doupdate(request,response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
*
*/
public void doupdate(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
// String Oder_no=request.getParameter("oder_nos");
// System.out.println("oder_no:"+Oder_no);
// Oder_inFactory oder_infac=new Oder_inFactory();
// Oder_inInter oder_ininter=oder_infac.getOder_inImpl();
// Oder_in oder_in =new Oder_in();
// oder_in=oder_ininter.queryOder_in(Oder_no);
//
//// request.setAttribute("oder_in", oder_in);
// response.sendRedirect(request.getContextPath()+"stock/order2002.jsp");
request.getRequestDispatcher("/stock/order2002.jsp").forward(request, response);
return ;
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
debug 跟踪request.getRequestDispatcher("/stock/order2002.jsp").forward(request, response);时报
2012-6-21 18:23:07 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet Oder_inServlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.csms.action.servlet.Oder_inServlet.doupdate(Oder_inServlet.java:144)
at com.csms.action.servlet.Oder_inServlet.doPost(Oder_inServlet.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
java.lang.IllegalStateException: Cannot forward after response has been committed原因:
request.getRequestDispatcher("/stock/order2002.jsp").forward(request, response);getRequestDispatcher是请求转发的意思,请求转发之后,后面就不能再重定向了,即不能再forward了
试一下呢
我试了一下,没用