Java 如何将调用从Servlet转发到Jsp文件

Java 如何将调用从Servlet转发到Jsp文件,java,jsp,servlets,java-ee-7,Java,Jsp,Servlets,Java Ee 7,我很抱歉改变了我的想法 我想将调用从Servlet转发到Jsp。在转发时间内,我将传递参数 Sevlet程序 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Creating object to FunctionNames class for calling their

我很抱歉改变了我的想法

我想将调用从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();
        }
    }
我怎样才能解决这个问题


谢谢

你的实际目的是什么?我们使用Wolfram Mathematica构建应用程序,我可以将Mathematica集成到JSP中,最后Mathematica代码在JSP文件中。它从QueryStringfromURL获取值。我们还有一个.exe文件,使用Java我可以运行.exe。一旦我运行.exe文件,它会将.txt文件作为输出。之后,如果我触发Mathematica应用程序,它会导入.exe输出文件并进行一些繁重的计算,最后一些数据将保存在DB中。。。。为什么需要迭代文件来完成这项工作?现在听起来您的体系结构有点崩溃。当您将forward与RequestDispatcher一起使用时,您基本上是在告诉容器您要转发到的资源应该完成对请求的处理。这应该是servlet方法中的最后一个方法调用,您不能将其放入循环中。@SotiriosDelimanolis谢谢您的回答。@Dave您是对的,我的体系结构完全崩溃了。在我的Kt中,有人提到了错误。谢谢您宝贵的建议。实际上,我想实现请求排队。如果我一次收到任意数量的请求,我需要保存队列中的所有内容,并一次释放一个请求。因为每个请求都运行相同的.exe文件。
<%
   out.print(request.getAttribute("Name"));
   out.print(request.getAttribute("Password"));
 %>
  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)