我正在运行一个 JSP 调用 servlet1 的应用程序。这个 servlet1 在内部调用 servlet2 来获取一些数据。Servlet 1 自己计算一些数据并从 servlet2 获取一些数据并将其发送回 JSP。
但我收到以下错误:
HTTP 状态 500 -
类型异常报告
信息
描述 服务器遇到一个内部错误 () 阻止它完成这个请求。
例外
java.lang.IllegalStateException:提交响应后无法转发 RoutingParser.doPost(RoutingParser.java:389) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) javax.servlet.http.HttpServlet.service(HttpServlet .java:847)
note Apache Tomcat/7.0.16 日志中提供了根本原因的完整堆栈跟踪。
我的代码是这样写的:
import java.awt.List;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import org.w3c.dom.Element;
//import javax.lang.model.element.Element;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import java.io.File;
import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
//import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
public class RoutingParser extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
System.out.println("Routing Parser is accessible");
System.out.println("i reached servlet");
try {
ArrayList inputlist1= new ArrayList();
inputlist1.add(request.getParameter("CardNetwork"));//CardNetwork
inputlist1.add(request.getParameter("Currency"));//Currency
inputlist1.add(request.getParameter("TxnCategory"));//TxnCategory
inputlist1.add(request.getParameter("TxnType"));//TxnType
ArrayList list1=new ArrayList();
ArrayList returnedData= new ArrayList();
System.out.println("i reached servlet");
try {
File fXmlFile = new File("c:\\eclipse\\RoutingTable.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
org.w3c.dom.Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("Entry");
System.out.println("-----------------------");
for (int temp = 0; temp < nList.getLength(); temp++)
{
//some piece of code
returnedData.add(data1);
returnedData.add(extra_info);
break;
}
}
/*it is important to remove the earlier node elements as the comparison starts from 0 all the time, we make a purely fresh arraylist for every node
* if we dont remove, the arraylist will keep on adding elements to the end and the comparison will not be made with latest node elements.
*/
for (int remove = 0; remove < 26; remove++){
list1.remove(0);
}
}
//this will be returned to JSP page
ServletContext context = this.getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/Mid");
// change your request and response accordingly
dispatcher.forward(request, response);
request.setAttribute("returndata",returnedData);
System.out.println("data1 set in arraylist for JSP page is: "+ returnedData.get(0));
System.out.println("extra_info set in arraylist for JSP page is: "+ returnedData.get(1));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("array list in end is: " + list1);
} finally {
RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher("/show_result_combination_2.jsp");
requestDispatcher.forward(request,response);
}
}
private static String getTagValue(String sTag, Element eElement) {
NodeList nlList = (eElement).getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
}
有人可以帮我解决这个错误。
提前致谢。