1

我很抱歉改变了我的整个概念。

我想将呼叫从转发ServletJsp。而转发时间我将传递参数。

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)

我怎样才能解决这个问题。

谢谢

4

0 回答 0