Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Servlets and RequestDispatcher.include()

Posted on 2001-09-13
2
Medium Priority
?
776 Views
Last Modified: 2013-11-24
Hi,

I am having a problem with the RequestDispatcher and the include() method.

Whenever I execute the include() method, the response gets comitted immediatly after finishing processing of the include. I have tried increasing the buffer size dramatically.  This prevents me from using the forward() method

I have just installed JRun 3.1 and this code now throws the following exception....(although it worked perfectly in Jrun 3.0 Sp2a.)

java.lang.IllegalStateException: Response has already been committed
        at allaire.jrun.servlet.JRunResponse.resetContent(../servlet/JRunResponse.java:172)
        at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1201)
        at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
        at com.concept.mercedes.servlet.DispatcherServlet.service(DispatcherServlet.java:102)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
        at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
        at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
        at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:39)
        at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)
        at allaire.jrun.session.JRunSessionService.service(../session/JRunSessionService.java:1082)
        at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)
        at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:89)
        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)
        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)
        at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)
        at allaire.jrun.jrpp.ProxyEndpoint.run(../jrpp/ProxyEndpoint.java:388)
        at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
        at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)

Through debugging I have narrowed it down to the commented lines in the souce below (look for NOTE...)

  public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    System.err.println("Executing DispatcherServlet...");

    response.setContentType("text/plain");

    String[] controllers = request.getParameterValues("controller");
    String view = request.getParameter("view");
    String originatingPageView = request.getParameter("originatingPageView");
    RequestDispatcher rd = null;

    try {
      // process all the controllers
      for (int i = 0; i < controllers.length; i ++) {

        rd = getServletContext().getRequestDispatcher(controllers[i]);

        if (rd == null) {
          System.err.println("DispatcherServlet error - No controller named : " + controllers[i]);
        } else {
          // invoke the controller
          System.err.println("Invoking : " + controllers[i]);
          // NOTE : response not commited here
          rd.include(request, response);
          // NOTE : response commited here
        }
      }

      // forward to the appropriate view appending any querystring info that might have been added to the request object
      QueryString qString = (QueryString)request.getAttribute("queryString");
      if (qString != null) {
        view = view + qString.toString();
      }

      rd = getServletContext().getRequestDispatcher(view);

      if (rd == null) {
        System.err.println("DispatcherServlet error - No view named : " + view);
      } else {
        System.err.println("Forwarding without errors : " + view);
        // NOTE : Fails here as already comitted.
        rd.forward(request, response);
      }

    } catch (ServletException e) {

      System.err.println("Root Cause --------------- : " + e.getRootCause());
      QueryString qString = (QueryString)request.getAttribute("queryString");
      // don't allow null values for qString object.
      if (qString == null) qString = new QueryString();

      if (e.getRootCause() instanceof InvalidParameterException) {

        // String redirect = originatingPageView;
        rd = getServletContext().getRequestDispatcher(originatingPageView + qString);

      } else if (e.getRootCause() instanceof SessionTimedOutException) {

        rd = getServletContext().getRequestDispatcher(loginView + qString);
      } else {

        rd = getServletContext().getRequestDispatcher(errorView + qString);
      }

      if (rd == null) {
        System.err.println("DispatcherServlet error - No errorView named : " + originatingPageView);
      } else {
        request.setAttribute("exception", e.getMessage());
        System.err.println("Forwarding with errors : " + errorView);
        rd.forward(request, response);
      }
    }
  }

If anyone has any insight, that would be great.
0
Comment
Question by:robinM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:robinM
ID: 6480883
I have just had a break through, deep in the depths of the allaire knowledge base is the following article which points to a hotfix.

                     http://www.allaire.com/Handlers/index.cfm?ID=21853&Method=Full

                     JRun Hot Fixes Build 16777

                     Fixes the following bug that was causing me errors...

                     26529 - 3.1 Regression. Servlet using getRequestDispatcher with an unbounded array of URLs causes "response has been closed" in Jrun 3.1. ex: RequestDispatcher dispatcher =
                     req.getRequestDispatcher(urlstrings);

                     After the install, all was good again....
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 6480906
Adding to PAQ Database
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question