我很抱歉改变了我的整个概念。
我想将呼叫从Servlet
转发到Jsp
。转发时间我会传递参数。
Sevlet计划。
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Creating object to FunctionNames class for calling their functions
try {
FunctionNames FunctionNamesObject=new FunctionNames();
//calling Method from class object
List<File> finalListNames=FunctionNamesObject.ListOfFileNames(getServletContext().getRealPath("/copy"),".txt");
for (int fileIndex = 0; fileIndex < finalListNames.size(); fileIndex++) {
//Copy and pasting file from SourcePath to destination Path
FunctionNamesObject.FileMoving(
finalListNames.get(fileIndex),
getServletContext().getRealPath("/Rod"),
"TMapInput.txt"
);
//.exe file process will be start from here.
FunctionNamesObject.ExeternalFileProcessing(getServletContext().getRealPath("/Rod"),"ThMapInfratab1-2.exe","TMapInput.txt");
//Later Rods output files moving from one directory to another function will be added here
request.setAttribute("Name","ABD");
request.setAttribute("Password", "DEF");
RequestDispatcher rd=request.getRequestDispatcher("/JSPFiles/JspTesting.jsp");
rd.forward(request, response ) ;
}
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Jsp代码是:
<%
out.print(request.getAttribute("Name"));
out.print(request.getAttribute("Password"));
%>
如果你观察我的代码,RequestDispatcher
代码在for
循环中,意味着对于每次迭代,我都希望使用参数转发到Jsp
文件。
在第一次迭代中,我收到来自Jsp
文件的响应,但它在第二次迭代时没有工作。我收到以下错误。
HTTP Status 500 - Cannot forward after response has been committed
java.lang.IllegalStateException: Cannot forward after response has been committed
PackageName.ClassName.service(ClassName.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
我该如何解决这个问题。
由于