Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I forward call from Servlet to Jsp file
    primarykey
    data
    text
    <p>I am sorry to change my entire concept.</p> <p>I want to forward call from <code>Servlet</code> to <code>Jsp</code>.While forwarding time I will pass parameters.</p> <p>Sevlet Program.</p> <pre><code> 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&lt;File&gt; finalListNames=FunctionNamesObject.ListOfFileNames(getServletContext().getRealPath("/copy"),".txt"); for (int fileIndex = 0; fileIndex &lt; 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(); } } </code></pre> <p>Jsp Code is:</p> <pre><code>&lt;% out.print(request.getAttribute("Name")); out.print(request.getAttribute("Password")); %&gt; </code></pre> <p>If you observe my code, <code>RequestDispatcher</code> code is in <code>for</code> loop,means For every iteration I want to forward call to <code>Jsp</code> file with parameters.</p> <p>in first iteration, I am getting response from <code>Jsp</code> file,but it's not working from second iteration.I am getting the following error.</p> <pre><code> 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) </code></pre> <p>How can I fix this.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload