OutputStream already obtained

Hi,
I am working on an application that uses struts on websphere.
I have written a code to download a file on click of a link. What it does is read the file and write it on an outputstream which I get from response object.
It works but gives the error java.lang.IllegalStateException: OutputStream already obtained
Now I know why this happening, you cannot get both outputstream and printwriter from same response object.
What I need is solution to get rid of this nasty error.
Please help... this is very critical and I am stuck up.
I tried looking at the net... but could not find any solution.
Thanks in advance,
Rana

Very simple.
Don't call getOuputStream() if you have already called getWriter().
You're writing a servlet, so you have full control over the code.
If you are writing it in JSP, make sure you have no text/carriage returns outside of <% %> tags.
ie
<%@page import="..."%>
<%@page import="..."%>
<% response.getOutputStream() %>
is bad because it gets the writer, has already been got, and written carriage returns before you call getOutputStream().
Hope this helps,
evnafets

Similar Messages

  • SRVE0199E: OutputStream already obtained when exporting pdf

    Hi,
    I am have a problem when export pdf file from a web application. When I build with tomcat every works fine, but when deployed in Websphere. The problem occurred. It is that the exception stack being attached at the end of pdf file which prevents Adobe Acrobat 7 from open and displaying message like the file is damaged and could not be repaired. This is the exception stack,
    <H1>Error page exception</H1>
    <H4>The server cannot use the error page specified for your application to handle the Original Exception printed below. Please see the Error Page Exception below for a description of the problem with the specified error page.</H4>
    <BR><H3>Original Exception: </H3>
    <B>Error Message: </B>SRVE0199E: OutputStream already obtained<BR>
    <B>Error Code: </B>500<BR>
    <B>Target Servlet: </B>action<BR>
    <B>Error Stack: </B><BR>
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    <BR>    
         at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter&#40;SRTServletResponse.java&#40;Compiled Code&#41;&#41;
    <BR>    
         at org.apache.jasper.runtime.JspWriterImpl.initOut&#40;JspWriterImpl.java&#40;Inlined Compiled Code&#41;&#41;
    <BR>    
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer&#40;JspWriterImpl.java&#40;Compiled Code&#41;&#41;
    <BR>    
         at org.apache.jasper.runtime.PageContextImpl.release&#40;PageContextImpl.java&#40;Compiled Code&#41;&#41;
    <BR>    
         at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext&#40;JspFactoryImpl.java&#40;Inlined Compiled Code&#41;&#41;
    <BR>    
         at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext&#40;JspFactoryImpl.java&#40;Compiled Code&#41;&#41;
    <BR>    
         at com.ibm._jsp._exportResults._jspService&#40;_exportResults.java:104&#41;
    <BR>    ... there is more...
    and my code that generate pdf is,
    try {
    out = res.getOutputStream();
    PdfWriter.getInstance(document, out);
    document.open();
    Paragraph para = null;
    para = new Paragraph("Title", FontFactory.getFont("Arial", 20,Font.BOLD));
    document.add(para);
    } catch (DocumentException e1) {
    e1.printStackTrace();
    } catch (IOException e1) {
    e1.printStackTrace();
    document.close();
    please help me out because this is an urgent issue. Thanks.

    I didn't put this code within JSP, but inside javax.servlet.jsp.tagext.TagSupport. Is this the same as in JSP?
    While waiting for the answer, I also find that in TagSupport, there is a member variable, pageContext, that also has pageContext.getOut() which is a JspWriter. This is used to export to excel. But for exporting to pdf, i used PdfWriter.getInstance(document, res.getOutputStream()); and res = pageContext.getResponse();
    is this the main reason?

  • WAS 6.0 - Response already committed / OutputStream already obtained

    Hello, we have struts code that is working fine in websphere 5, but not 6. I've seen this same kind of thing being post around, but haven't found one that closely resembles our simple setup. Below I've copied what our code looks like. Please help me to understand what the least-intrusive way would be to fix something simple like this, and let me know if more info is needed. FYI, we have tried returning null from the class, but this doens't seem to work. Also, some additional info is that we need this to work in WAS 5 and 6, because we have two different apps containing the same code, one of which is deployed (via EAR file) on 5 and the other 6. Thanks!
    struts-config entry:     
    <action path="/streamFile" type="MyClass" scope="request" validate="false">
                  <forward name="success" path=""/>
    </action>     
    web.xml entry:
         <servlet-mapping>
              <servlet-name>opsconsoleServlet</servlet-name>
              <url-pattern>streamFile</url-pattern>
         </servlet-mapping>
    Snippet of Class file:
    public class MyClass extends Action {
         public ActionForward execute(ActionMapping mapping,
                         ActionForm form,
                        HttpServletRequest request,
                        HttpServletResponse response)
              throws Exception {    
         ServletOutputStream out = response.getOutputStream();
         BufferedOutputStream bos = null;
         try {
                   bos = new BufferedOutputStream(out);
                    bos.write(<bytes, etc>);
         } catch(final MalformedURLException e) {
         throw e;
         } catch(final IOException e) {
         throw e;
         } finally {
         if (bos != null)
              bos.close();
         if (out != null)
              out.close();
         return mapping.findForward("success");
    error from log:
    [11/5/07 12:50:11:737 EST] 00000036 ServletWrappe E   SRVE0014E: Uncaught service() exception root cause FilterProxyServlet: Cannot forward. Response already committed.
    [11/5/07 12:50:12:001 EST] 00000036 ServletWrappe E   SRVE0068E: Could not invoke the service() method on servlet opsconsoleServlet. Exception thrown : javax.servlet.ServletException: Cannot forward. Response already committed.
            at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:157)
            at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:82)
    error later in log:
    [11/5/07 12:50:12:621 EST] 00000036 SRTServletRes W   WARNING: Cannot set status. Response already committed.
    [11/5/07 12:50:12:627 EST] 00000036 SRTServletRes W   WARNING: Cannot set header. Response already committed.
    [11/5/07 12:50:14:191 EST] 00000036 ServletWrappe A   SRVE0242I: [Communication] [/OpsConsole] [/WEB-INF/jsp/error/internalError.jsp]: Initialization successful.
    [11/5/07 12:50:14:201 EST] 00000036 ServletWrappe E   SRVE0068E: Could not invoke the service() method on servlet /WEB-INF/jsp/error/internalError.jsp. Exception thrown : java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
            at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java:490)
            at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:170)
            at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:163)
            at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:227)

    svguerin3 :
    So this is something that worked in websphere 5 but not 6.. Are you sure this same code working on WAS5? This shouldn't. I guess you are trying to display the contents of the stream in a JSP page.If that's correct don't use
    ServletOutputStream out = response.getOutputStream();
         BufferedOutputStream bos = null;
         try {
                   bos = new BufferedOutputStream(out);
                    bos.write(<bytes, etc>);
         }instead read the bytes in to an in memory object, add this in memory object to request param and then call findForward(). In the JSP page get this request attribute and do whatever you want.
    Note: You can either use servletoutstream.write or RequestDispactcher.forward/redirect/response.sendRedirect.

  • Erro code:500 SRVE0199E: OutputStream already obtained

    Hi all Iam writing a JSP code for exporting the result in to the csv .It working perfectly but afte exporting results it is showing exeception on same csv file.Can any one help me.The exeception is shown bellow.
    Error page exception
    The server cannot use the error page specified for your application to handle the Original Exception printed below. Please see the Error Page Exception below for a description of the problem with the specified error page.
    Original Exception:
    Error Message: SRVE0199E: OutputStream already obtained
    Error Code: 500
    Target Servlet: /quantum/ExportToCsv.jsp
    Error Stack:
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    " at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java(Compiled Code))"
    " at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java(Inlined Compiled Code))"
    " at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java(Compiled Code))"
    " at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java(Compiled Code))"
    " at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java(Inlined Compiled Code))"
    " at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java(Compiled Code))"
    " at com.ibm._jsp._ExportToCsv._jspService(_ExportToCsv.java:321)"
    " at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))"
    " at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))"
    " at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java(Inlined Compiled Code))"
    " at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))"
    Error Page Exception:
    Error Message: SRVE0199E: OutputStream already obtained
    Error Code: 0
    Target Servlet: null
    Error Stack:
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    " at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.webapp.WebApp.sendError(WebApp.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))"
    " at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))"
    " at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))"

    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    " at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java(Compiled Code))" Read the API docs. You cannot get both OutputStream and Writer during one request-response cycle. Do the one or the other. The exception tells that you're trying to get the Writer while somewhere before that line the OutputStream is already been obtained.
    The solution is hopefully obvious: change your code so that it only get the Writer, or only the OutputStream, not both. I recommend getting the OutputStream all the time and don't even think about getting the Writer. Most API's also do it.

  • OutputStream already obtained]: java.lang.IllegalStateException: OutputStre

    Hi,
    I was trying to use OutputStream object in a JSP page.
    [Servlet Error]-[OutputStream already obtained]: java.lang.IllegalStateException: OutputStream already obtained
    I have done opstream.flush() and opstream.close() before and after the usage resp.
    Please advise me what has to be done.
    Thanks

    I think the problem is that when the JSP page is converted into servlet it adds some extra
    out.write("\r\n");
    to avoid this do not leave and space between the ending and starting of scriplet tags.
    Ex: If u have something like this
    <%@page buffer="none" errorPage="errorpage.jsp" %>
    <%
    %>
    then change it to
    <%@page buffer="none" errorPage="errorpage.jsp" %><%
    %>
    Tell me if this works....else post the code.

  • Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error

    hi
    i m unable to fugure out y I m getting this error
    it's a suggestion page and on submitting this page I have to reload the page but with status of the page (requires approval) in form of url
    earlier say few days back , it was working fine , i had absolutely no issues in this
    since 2-3 days everytime i submit the page , i m getting the error
    Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error 500
    my code is listed below
    pls help
    <%@ include file="../includes/sessionChecker.jsp"%>
    <%@ page isThreadSafe="false" errorPage="../html/messError.jsp" %>
    <%@ page import="java.io.*,java.util.*,java.sql.*" %>
    <%@ page import="com.syntaxsoft.util.*" %>
    <%@ page import="com.syntaxsoft.util.DateUtil" %>
    <%@ page import="com.syntaxsoft.admin.*" %>
    <%@ page import="com.syntaxsoft.employee.*" %>
    <%@ page import="com.syntaxsoft.db.*" %>
    <%@ include file="../includes/cssJsInclude.jsp"%>
    <%@ taglib uri="QuinnoxTags" prefix="QuinnoxTags" %>
    <html>
    <head>
    <title>Suggestions</title>
    <meta http-equiv="Content-Type" content="xls/html; charset=iso-8859-1">
    <link href="../STYLESHEET/stylesheet.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <%!
         Table sqltab;
         SqlBuilder sqlObj;
    %>
    <%
         String dofc = "",subject="",suggestion = "",docsrno="",actions="";
         String pick_button = "",locateid = "",employid="",url="";
         String employeeid="";
         String tabname=" ";
         boolean success = false;
         ResultSet rs= null;
    %>
    <%
         employid = (String) session.getAttribute("empid");
         locateid = (String) session.getAttribute("locationid");
         Employee empobj = Employee.getEmployee(employid);
         DateUtil dateform = new DateUtil(locateid);
         actions = request.getParameter("actions");
         pick_button = request.getParameter("DECISION");
         System.out.println("ACTION"+actions);
         System.out.println("pick_button"+pick_button);
    %>     
    <body>
    <%
         if(actions.equals("create")){
              if(pick_button == null){
    %>     
                   <form name="form1" method="post" action="../HRFiles/Suggestions.jsp">
                        <input type="hidden" name="actions" value="<%=actions%>">
                   <div class="page_heading">Suggestion Box</div><br>
                   <table>
                        <tr><th>From:</th><td><%=empobj.getFullName()%></td></tr>
                        <tr><th>Dated:</th><td><%=dateform.getToday()%></td></tr>
                        <tr><th>Subject</th><td><QuinnoxTags:TextBox type="text" name="subject" maxLength="65" required="true" value=" " label="Subject"/></td></tr>
                        <tr><th colspan="2">Suggestion:</th></tr>
                        <tr><td colspan="2"><QuinnoxTags:TextBox name="suggestion" type="textarea" cols="60" rows="13" required="true" value=" " label="Suggestion" maxLength="250"/></td></tr>
                   </table><br>
                   <table>
              <tr>
                   <td align="right">
                        <input type="submit" name="DECISION" value="Submit" class="button">
                   </td>
              </tr>
         </table>
                   <input type="hidden" name="empid" value="<%=employid%>"
                   <jsp:include page="../masters/flow.jsp" flush="true">
                        <jsp:param name="CREATOR" value="true"/>
                        <jsp:param name="TABNAME" value="SUGGESTION_WKFLOW"/>
                   </jsp:include>               
    <!--               <table>
                        <tr><td align="right"><input type="submit" name="submit" value="Submit" class='button'></td></tr>
                   </table>-->
              </form>
    <%
              else{
                   dofc          = dateform.getTodayMillis()+"";
                   subject          = request.getParameter("subject");          
                   suggestion     = request.getParameter("suggestion");
                   tabname =request.getParameter("TABNAME");          
                   // insert into SUGGESTIONS
                   // generate key
                   IDs idObj = IDs.getIDs();
                   docsrno = idObj.getId("SUGGESTIONID");
                   sqlObj=new SqlBuilder("SUGGESTIONS");
                   sqlObj.setColumn("DOCSLNO",docsrno);
                   sqlObj.setColumn("EMPID",employid);
                   sqlObj.setColumn("DOFC",dofc);
                   sqlObj.setColumn("DOFCZONE",locateid);
                   sqlObj.setColumn("SUBJECT",tabname);
                   sqlObj.setColumn("SUGGESTION",suggestion);
    //          System.out.println("empid is "+request.getParameter("empid"));
                   System.out.println("empid is "+employid);
                   success = sqlObj.set(SqlBuilder.INSERT);
    %>                         
                   <jsp:include page="../masters/flow1.jsp" flush="true">
                        <jsp:param name="DECISION" value="<%=request.getParameter(com.syntaxsoft.admin.WorkFlow.DECISION)%>" />
                        <jsp:param name="empid" value="<%=request.getParameter(\"empid\")%>" />
                        <jsp:param name="VIEWLEVEL" value="<%=request.getParameter(com.syntaxsoft.admin.WorkFlow.VIEWLEVEL)%>" />
                        <jsp:param name="VIEWERID" value="<%=request.getParameter(com.syntaxsoft.admin.WorkFlow.VIEWERID)%>" />
                        <jsp:param name="COMMENTS" value="<%=request.getParameter(com.syntaxsoft.admin.WorkFlow.COMMENTS)%>" />
                        <jsp:param name="DOCSLNO" value="<%=docsrno%>"/>
                        <jsp:param name="CREATOR" value="true"/>
                        <jsp:param name="TABNAME" value="<%=request.getParameter(\"TABNAME\")%>" />
                        <jsp:param name="MASTER_TABLE" value="SUGGESTIONS" />
                   </jsp:include>
                   <jsp:include page="../includes/redirectInclude.jsp" flush="true">
                        <jsp:param name="url" value="../HRFiles/ViewSuggestion.jsp?flag=empview" />
                   </jsp:include>
    <%
              } // end of if(pick_button == null)
         } // end of if(actions == create)
         if(actions.equals("select")){
              rs = sqltab.select("select * from SUGGESTIONS");
              if(rs.next()){
    %>
                   <div class="page_heading">List of Suggestions</div><br>
                   <table>
                        <tr>
                             <th>Employee Id</th>
                             <th>Employee Name</th>
                             <th>Suggestion Date</th>
                             <th>Subject</th>
                        </tr>
    <%          
                   do{
                        docsrno = rs.getString("DOCSLNO");
                        employeeid = rs.getString("EMPID");
                        dofc = rs.getString("DOFC");
                        subject = rs.getString("SUBJECT");
                        Employee empobj1 = Employee.getEmployee(employeeid);
                        url = "../HRFiles/Suggestions.jsp?actions=view&docsrno="+docsrno;
    %>
                        <tr>
                             <td><a href="<%=url%>"><%=employeeid%></a></td>
                             <td><a href="<%=url%>"><%=empobj1.getFullName()%></a></td>
                             <td><a href="<%=url%>"><%=dateform.getDate(dofc)%></a></td>
                             <td><a href="<%=url%>"><%=subject%></a></td>
                        </tr>                    
    <%               
                   }while(rs.next());
              } // end of if
         } // end of if(actions == select)
         if(actions.equals("view")){
              docsrno = request.getParameter("docsrno");
              rs = sqltab.select("select * from SUGGESTIONS where DOCSLNO='"+docsrno+"'");
              if(rs.next()){
                   do{
                        docsrno = rs.getString("DOCSLNO");
                        employeeid = rs.getString("EMPID");
                        dofc = rs.getString("DOFC");
                        subject = rs.getString("SUBJECT");
                        suggestion = rs.getString("SUGGESTION");
                   }while(rs.next());
              } // end of if()
              Employee empobj2 = Employee.getEmployee(employeeid);
    %>
              <div class="page_heading">Suggestion Box</div><br>
              <table>
                   <tr><th>From:</th><td><%=empobj2.getFullName()%></td></tr>
                   <tr><th>Dated:</th><td><%=dateform.getDate(dofc)%></td></tr>
                   <tr><th>Subject</th><td><%=subject%></td></tr>
                   <tr><th colspan="2">Suggestion:</th></tr>
                   <tr><td colspan="2"><textarea name="suggestion" cols="70" rows="10" readonly><%=suggestion%></textarea></td></tr>
              </table><br>
              <table>
                   <tr><td colspan="4" align="right">Back</td></tr>
              </table>
    <%     
         } // end of if(actions == view)
    %>
    </body>
    </html>
    rgds

    The problem is that you are trying to do a forward somewhere when output has already been sent to the browser: this is not allowed. I cannot find it in your code, so it must be in one of the includes.

  • Cannot forward. Writer or Stream already obtained.

    hi Friends,
    had a small doubt to clarify
    I am using jsp:include tag to include a jsp page within a jsp
    <jsp:include page="../includes/empHeader.jsp" flush="true">
    <jsp:param name="empid" value="<%=empid%>"/>
    </jsp:include>
    <jsp:include page="../leave/leaverecordcomponent.jsp" flush="true">
    <jsp:param name="empid" value="<%=empid%>"/>
    </jsp:include>
    I am able to view empHeader.jsp but unable to view leaverecordcomponent.jsp
    I m getting this error
    Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error 500:
    However if i replace
    <jsp:include page="../leave/leaverecordcomponent.jsp" flush="true">
    by
    <jsp:include page="../employee/Skills.jsp" flush="true">
    then i can view empHeader.jsp and then Skills.jsp
    What's to be done ?
    Thanx

    I am guessing that "../leave/leaverecordcomponent.jsp" does a forward, either through a controller servlet, a filter, or on the page it self.
    What can you do? Prevent ../leave/leaverecordcomponent.jsp from doing a forward, because once the response is commited (something writtent to it), then you can not forward.

  • OutputStream already retrieved?

    Hi , all:
    Now i use the popup dialog to export excel , after export the data , i use AdfFacesContext.getCurrentInstance().returnFromDialog(null, null); back to the main page.but when the program run this, it will has error as follows:
    javax.faces.FacesException: #{excelExporter.doExport}: javax.faces.el.EvaluationException: java.lang.IllegalStateException: OutputStream already retrieved
    and when i export excel, i use these code:
    try {
    OutputStream out = response.getOutputStream();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    HSSFWorkbook workbook = createWorkbook(iter, attr, attributes, maxrowcount);
    workbook.write(out);
    out.flush();
    out.close();
    FacesContext.getCurrentInstance().responseComplete();
    } catch (IOException ex) {
    ex.printStackTrace();
    createWorkbook is the method to generate the excel.
    After this i will call the AdfFacesContext.getCurrentInstance().returnFromDialog(null, null); to return and at this time it has error.
    How to solve this problem.
    Thanks in advance.

    Hi,
    what I am suggesting is to defer the whole Excel processing to the return listener. The data entered in the dialog can be returned to the return listener in a HashMap (second argument in the closeDialog statement). Then you handle Excel generation etc. in the listener code. My assumption is that you are getting into conflict with the internal dialog processing. From the application's workflow there is no difference between your approach and what I am suggesting
    Frank

  • InputStream and OutputStream - Already opened for input

    URL url = new URL("website.com");
            URLConnection urlc = url.openConnection();
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
    // read something from a file
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            while (reader.read() > 0) {
                // do something
            reader.close();
    // write something to the same file
            DataOutputStream dos = new DataOutputStream(urlc.getOutputStream());
            dos.writeBytes("write something");
            dos.close();"java.io.IOException: Already opened for input:"
    what is that supposed to mean? Doesn't "reader.close();" take care of that?
    I can read the file and I can write to a file. But I can't do both one after another...
    Why is that?

    I just swapped the code
    URL url = new URL("website.com");
            URLConnection urlc = url.openConnection();
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
    // write something to the same file
            DataOutputStream dos = new DataOutputStream(urlc.getOutputStream());
            dos.writeBytes("write something");
            dos.close();
    // read something from a file
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            while (reader.read() > 0) {
                // do something
            reader.close();

  • Error - OutpustStream already obtained

    Hi folks
    this is the message I get with my servlet, It's very strange. I get this error only with WebSphere 6, with other platform (Tomcat, Weblogic) I've no problems.
    Here's the code, it's very simple.
    this is the "end" of the servlet
                                                        response.setContentType("application/octet-stream");
                                                         response.setContentLength(lung);
                                                         response.setBufferSize(lung);
                                                         ServletOutputStream sos=                                                   sos=response.getOutputStream();
                                                         byte[] buffer=new byte[lung];
                                                         fis.read(buffer);
                                                         fis.close();
                                                        sos.write(buffer);
                                                        sos.flush();
    [......]and the ather one is the jsp
       request.setAttribute("xml",contenuto);
                RequestDispatcher rd =    getServletConfig().getServletContext().getRequestDispatcher("/myServlet");
                        rd.forward(request,response);
                } else {
    [....]I haven't getWriter before. This thing drive me crazy
    anyone can help me?
    Thanks
    Lorenzo

    The problem is that you are trying to do a forward somewhere when output has already been sent to the browser: this is not allowed. I cannot find it in your code, so it must be in one of the includes.

  • Java.lang.IllegalStateException: OutputStream already retrieved

    I'm getting this error when I execute the line
    response.getWriter().write("yes");why is this the case and how do I correct it?

    this is all the code in my JSP, so I'm quite certain I only called it once.
    <%
    String strUser = request.getParameter("username");
    String strPassword = request.getParameter("password");
    if(strUser != null && strPassword != null) {
        //System.out.println("before sending response");
         response.setContentType("text/xml");
         response.setHeader("Cache-Control", "no-cache");
        // for plain text response:
         //response.getWriter().write("yes");
        // Or for XML formatted response:
         response.getWriter().write("<message>yes</message>");   
        //System.out.println("after sending response");          
    } else {
         //nothing to show
         response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    %>is there any other reason for this exception?

  • Error while sending a text file to client as attachment

    I want to download a file on clicking a button. Here is my button code
    <input type="button" onClick="showdownloadwindow()" value="Download My file">
    The java script showdownloadwindow() should invoke a jsp that has code to construct the text file to be downloaded
    Here is the javascript function
    <script>
         function showdownloadwindow()
              var url = 'http://<%=request.getServerName()%>'+':'+<%=request.getServerPort()%>+'/downloadtextfile.jsp';     
              window.open(url,"","");
    </script>
    the downloadtextfile.jsp looks something like this
    <%
              response.setContentType("text/plain");
              response.setHeader("Content-disposition","attachment; filename=myfile.txt" );
              BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
              String temp="Put some text string for now";
              bos.write(temp.getBytes());
              bos.flush();
              bos.close();
              response.flushBuffer();
    %>
    i have two problems
    1. when the button "Download My file" is clicked a separate window is opened and then the save file dialog box appears. How can I change my code
    so that it only shows download window only ( not another browser window)
    2. myfile.txt contains some error in addition to the temp string
    Here is the error from myfile.txt
    <BR><H3>Original Exception: </H3>
    <B>Error Message: </B>SRVE0199E: OutputStream already obtained<BR>
    <B>Error Code: </B>500<BR>
    <B>Target Servlet: </B>/downloadtextfile.jsp<BR>
    <B>Error Stack: </B><BR>
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    <BR>    
         at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter&#40;SRTServletResponse.java:467&#41;
    <BR>    
         at org.apache.jasper.runtime.JspWriterImpl.initOut&#40;JspWriterImpl.java:170&#41;
    <BR>    
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer&#40;JspWriterImpl.java:163&#41;
    <BR>    
         at org.apache.jasper.runtime.PageContextImpl.release&#40;PageContextImpl.java:217&#41;
    <BR>    
         at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext&#40;JspFactoryImpl.java:149&#41;
    <BR>    
         at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext&#40;JspFactoryImpl.java:117&#41;
    <BR>    
         at com.ibm._jsp._downloadtextfile._jspService&#40;_downloadtextfile.java:93&#41;
    <BR>    
         at com.ibm.ws.jsp.runtime.HttpJspBase.service&#40;HttpJspBase.java:88&#41;
    <BR>    

    > Channel FILE_TLE_Sender_SalesOrder_CC: Empty document found - proceed without sending message.
    > Can someone tell me why this error is happening? 
    Maybe your source file is empty?
    This is exact what the error message says.

  • Downloading a file via JSP

    I am trying to write some code which will generate a file and then download the file
    from my Webserver. When I download the file I get "Error 500: OutputStream already obtained"
    appended to the file. I can't work out why this is so.
    Here is the code I have used to download the file.
    I have also included the file before and after transmission.
    Any help would be appreciated.
    <%@page import="java.net.*,javax.servlet.http.*,javax.servlet.*,java.io.*" %>
    <%
    ServletOutputStream out1 = response.getOutputStream();
    String fileName = (String)request.getParameter("filename");
    // MIME type for pdf doc
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition","attachment;filename="+fileName+";");
    File f = new File("\\"+fileName);
    FileInputStream stream = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(stream);
    BufferedOutputStream bos = new BufferedOutputStream(out1);
    byte[] buff = new byte[2048];
    int bytesRead;
    // Simple read/write loop.
    try {
    while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
    bos.write(buff, 0, bytesRead);
    } catch (Exception e) {
    if (bos != null) bos.close();
    e.printStackTrace();     
    finally {
    if (bis != null) bis.close();
    if (bos != null) bos.close();     
    if (stream != null) stream.close();     
    %>
    This is the file on the WebServer
    The Quick Brown Fox Jumps Over The Lazy Dog
    The Quick Brown Fox Jumps Over The Lazy Dog
    The Quick Brown Fox Jumps Over The Lazy Dog
    This is the file after it has been transferred
    The Quick Brown Fox Jumps Over The Lazy Dog
    The Quick Brown Fox Jumps Over The Lazy Dog
    The Quick Brown Fox Jumps Over The Lazy DogError 500: OutputStream already obtained
    Thanks
    Adrian Campbell
    Honda Australia

    The JSP automatically gets an outputstream/writer, and starts writing to the output. In fact thats where the implicit variable "out" comes from.
    Couple of things to be aware of:
    Every carriage return outside of a <% %> tag in a JSP gets converted directly into the html as out.println("\r\n");
    That means the generated servlet has started writing even before you get the outputstream - which is what raises the exception.
    There are two ways to stop this
    1 - write it in a servlet - its purely code, with no HTML so servlet is better suited.
    2 - have no carriage returns outside of JSP tags <% %>. You currently have one - one the very first line. Try it like this:
    <%@page import="java.net.*,javax.servlet.http.*,javax.servlet.*,java.io.*" %><% 
    ServletOutputStream out1 = response.getOutputStream();
    %>  // and no carriage return at the end eitherThat should do it.
    As an aside, if you are going to be generating a text file, then you can use the implicit writer "out" as opposed to the OutputStream.
    Cheers,
    evnafets

  • Java.io.EOFException: Unexpected end of ZLIB input stream

    Hi,
    I am reading .gz file in servlet and writing it in output stream. It works fine for smaller files. For larger file when I reading file and writing output I am getting exceptions as below in order.
    8/6/09 9:52:28:953 CDT] 00000029 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /WEB-INF/pages/TilesTemplate/layouttemplate.jsp. Exception thrown : java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
         at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java:489)
         at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:170)
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:163)
         at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:227)
    ---- Begin backtrace for Nested Throwables
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
         at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter(SRTServletResponse.java:489)
         at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:170)
         at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:163)
    *[8/6/09 9:52:28:625 CDT] 00000029 SystemErr R java.io.EOFException: Unexpected end of ZLIB input stream*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:238)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:157)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:109)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.io.FilterInputStream.read(FilterInputStream.java:110)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:325)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:223)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.io.InputStreamReader.read(InputStreamReader.java:208)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.io.BufferedReader.fill(BufferedReader.java:153)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.io.BufferedReader.readLine(BufferedReader.java:316)*
    *[8/6/09 9:52:28:656 CDT] 00000029 SystemErr R      at java.io.BufferedReader.readLine(BufferedReader.java:379)*
    *[8/*

    My suggestion would be to run your code as a plain old Java application. Why use a servlet environment to test the problem? There's just too many things going on. So first see if it works the same way in a Java application. If it does, or if it doesn't, you then know where to go next.

  • Oracle BI Publisher - can not access Shared Folder , using Oracle BI Server

    Hi there,
    We have an installed OBIEE and BIP (BI Publisher) system which is the security setting of BIP using "Oracle BI Server".
    Our OBIEE security is using the combination of LDAP (authentication) and Relational Table (for grouping user privillege)
    The integration connection between OBIEE and BIP is successfull, and I can connect using Administrator to the BIP
    But when I assign a general user using group : XMLP_Admin (define in rpd file and relational table), the user can log in to BIP, but can NOT access the Shared Folder.
    the error desc : "Error 500: SRVE0199E: OutputStream already obtained"
    Anyone can help ?
    Thanks a lot
    -toni

    Did you define Roles and Permissions to the shared folder from BIP Admin?
    -Prakash

Maybe you are looking for

  • Warning messages after repairing permissions

    I hope that someone out there can tell me what these messages mean after running Disk Utility on my new MBP. Here is what it says: Repairing permissions for “Mac HD” Warning: SUID file "usr/libexec/load_hdi" has been modified and will not be repaired

  • Conky can't run since upgrade to Plasma 5

    I just upgraded to KDE Plasma 5. For some reason I can't seem to run conky anymore and I'm not sure why. $ conky Conky: desktop window (2200011) is subwindow of root window (ab) Conky: window type - override Conky: drawing to created window (0x3e0000

  • No pics showing in iPhoto library

    Hello, I would really appreciate it if anyone has any ideas on how to solve this. I keep my iPhoto library on an external drive. I have been doing this for some time, and I have not had any problems. Today, however, I plugged in the external hard dri

  • ADF ViewObject Clarifications

    Hello, I'm facing strange behaviours in ADF viewobject. I have a viewobject PropertyView1. I need to list the properties only for a particular user. And also within that , I need to display based on the property status. So I have a dataaction (DA1) w

  • MP4 video

    Why can't I use my ipad2 without having to connect to a computer?  I purchased a MP4 video but I can't download and view it because my old laptop lost it's Internet capability, so I can't sync it.  Suggestions?