Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTP状态500-提交响应后无法转发_Java_Jakarta Ee_Servlets - Fatal编程技术网

Java HTTP状态500-提交响应后无法转发

Java HTTP状态500-提交响应后无法转发,java,jakarta-ee,servlets,Java,Jakarta Ee,Servlets,我该如何着手解决这个问题?我已经尝试了很多事情,在这里用同样的问题看了很多不同的事情,但我不能解决它。有人能解释一下发生了什么事吗。如果有帮助的话,我希望客户提交一个表单,一旦他们提交了表单,它就会转到servlet并将其发送到一个收据,在那里他们可以看到他们输入的信息。如果有更简单的解决办法,我洗耳恭听 下面是stacktrace Mar 31, 2014 2:40:17 PM org.apache.catalina.core.StandardWrapperValve invoke SEVER

我该如何着手解决这个问题?我已经尝试了很多事情,在这里用同样的问题看了很多不同的事情,但我不能解决它。有人能解释一下发生了什么事吗。如果有帮助的话,我希望客户提交一个表单,一旦他们提交了表单,它就会转到servlet并将其发送到一个收据,在那里他们可以看到他们输入的信息。如果有更简单的解决办法,我洗耳恭听

下面是stacktrace

Mar 31, 2014 2:40:17 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [edu.witc.Assignment03.controller.CustomerServlet] in context with path [/Justin_EJ_Assignment03_15400579] threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:348)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
    at edu.witc.Assignment03.controller.CustomerServlet.sendCustomerInfo(CustomerServlet.java:85)
    at edu.witc.Assignment03.controller.CustomerServlet.doPost(CustomerServlet.java:139)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
SERVLET
包edu.witc.Assignment03.controller;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.Collection;
导入java.util.List;
导入javax.servlet.*;
导入javax.servlet.annotation.WebServlet;
导入javax.servlet.http.HttpServlet;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
//导入javax.servlet.annotation.WebServlet;
//导入javax.servlet.http.HttpServlet;
//导入javax.servlet.http.HttpServletRequest;
//导入javax.servlet.http.HttpServletResponse;
导入javax.servlet.http.HttpSession;
导入edu.witc.Assignment03.model.Customer;
导入edu.witc.Assignment03.model.Phone;
导入edu.witc.Assignment03.model.States;
@WebServlet(description=“servlet获取表单和模型之间的控制器”,urlPatterns={”/customerServlet“})
公共类CustomerServlet扩展了HttpServlet{
私有静态最终长serialVersionUID=1L;
公共CustomerServlet(){
超级();
}
私有void processRequest(HttpServletRequest请求,
HttpServletResponse响应)引发ServletException,IOException{
//TODO自动生成的方法存根
HttpSession session=request.getSession();
//创建JavaStudents对象
电话=新电话();
//申报学生收藏
Collection phones=phone.getPhoneCollection();
//充实arraylist中的收藏
//students=newjavastudents().getStudents();
//System.out.println(“嘿”+students.size());
//在会话中存储JavaStudents对象
//if(会话!=null){
session.setAttribute(“电话”,电话);
getRequestDispatcher(“/customerManagement.jsp”).forward(请求,响应);
//}
}
private edu.witc.Assignment03.model.States=新州();
private List customers=new ArrayList();
私有void addCustomer(HttpServletResponse,HttpServletRequest)//重定向到索引
抛出IOException、ServletException{
字符串url=“/receive.jsp”;
request.setAttribute(“客户”,客户);
getRequestDispatcher(url).forward(请求,响应);
}
私有void editCustomer(HttpServletResponse,HttpServletRequest)//重定向到索引
抛出IOException、ServletException{
字符串url=“/customerManagement.jsp”;
request.setAttribute(“客户”,客户);
getRequestDispatcher(url).forward(请求,响应);
}
私有void sendCustomerInfo(HttpServletResponse,HttpServletRequest)//重定向到索引
抛出IOException、ServletException{
字符串url=“/receive.jsp”;
request.setAttribute(“客户”,客户);
getRequestDispatcher(url).forward(请求,响应);
}
私人客户getCustomer(int customerId){
用于(客户:客户){
if(customer.getCustomerId()==customerId){
退货客户;
}
}
返回null;
}
私有void sendEditCustomerForm(HttpServletRequest请求,
HttpServletResponse响应)引发IOException,ServletException{
字符串url=“/customerManagement.jsp”;
request.setAttribute(“客户”,客户);
getRequestDispatcher(url).forward(请求,响应);
}
public void doPost(HttpServletRequest请求,
HttpServletResponse(响应)
抛出ServletException、IOException{
processRequest(请求、响应);
//更新客户
int customerId=0;
试一试{
客户ID=
Integer.parseInt(request.getParameter(“id”);
}捕获(数字格式){
}
Customer=getCustomer(customerId);
如果(客户!=null){
customer.setFirstName(request.getParameter(“firstName”);
customer.setLastName(request.getParameter(“lastName”);
customer.setEmail(request.getParameter(“电子邮件”));
customer.setPhone(request.getParameter(“phone”);
customer.setAddress(request.getParameter(“地址”);
customer.setCity(request.getParameter(“city”);
customer.setZip(request.getParameter(“zip”);
}
sendCustomerInfo(响应、请求);
}
}

在没有看到任何代码的情况下,很难告诉您该做什么。然而,这里发生的是:

  edu.witc.Assignment03.controller.CustomerServlet.sendCustomerInfo(CustomerServlet.java:85)
您正在将响应转发到其他内容

但是,您之前在回复中发送了一些内容。这是你做不到的。您必须发送响应,或者将请求转发给其他人。不能同时执行这两项操作。

doPost()
方法中,您使用以下两种方法发送响应

processRequest(request, response);
sendCustomerInfo(response, request);

因此,在调用
sendCustomerInfo(response,request)
时,您将得到此异常,因为响应已由
processRequest
方法提交。

让我上传代码吧,我忘了这么做,我的错误!好的,那么如果我不能使用processrequest方法,我将如何加载选项列表呢。我需要加载选项列表,然后当用户点击submit时,他们可以使用输入的信息进入收据页面
processRequest(request, response);
sendCustomerInfo(response, request);