title: Spring portlet get jsp response as string
body: <p>Spring portlet JSP, Making ajax request and in controller trying to get jsp page so that i can pass and generate pdf output.</p>
  
  <p>But problem is didn't get any string data but html contents are returned on jsp page please check code as follwoing</p>
  
  <pre><code>@Controller("exportSummaryController")
  @RequestMapping(value = "VIEW")
  public class ExportSummaryController implements PortletConfigAware  {
  
      @ResourceMapping("exportAccRequest")
      public void accountRollupAction(@RequestParam("accNum") String accNum, 
          @RequestParam("sourceId") String sourceId, @RequestParam("serviceId") String serviceId, 
          @RequestParam("summaryExport") String strExport, ResourceRequest request, ResourceResponse response) throws Exception {
  
          //processing data
  
          ResourceResponseWrapper responseWrapper = new ResourceResponseWrapper(response) {
              private final StringWriter sw = new StringWriter();
  
              @Override
              public PrintWriter getWriter() throws IOException {
                  return new PrintWriter(sw);
              }
  
              @Override
      public OutputStream getPortletOutputStream() throws IOException {
                  return(new StringOutputStream(sw));
              }
              @Override
              public String toString() {
                  return sw.toString();
              }
  
          };
  
          portletConfig.getPortletContext().getRequestDispatcher("/WEB-INF/jsp/account_summary.jsp").include(request, responseWrapper);
          String content = responseWrapper.toString();
          System.out.println("Output : " + content); // here i found empty output on command line but output is returned to jsp page.
      }    
  }
  
  public class StringOutputStream extends OutputStream {
          private StringWriter stringWriter;
  
          public StringOutputStream(StringWriter stringWriter) {
              this.stringWriter = stringWriter;
          }
  
          public void write(int c) {
              stringWriter.write(c);
          }
      }
  </code></pre>