Re: getOutputStream() has already been called for this response

2013-01-18 Thread S S
Hi,

I am also facing the same problem while trying to download to excel. Plz let
me know what code u have added to solve this problem



--
View this message in context: 
http://struts.1045723.n5.nabble.com/Cannot-forward-after-response-has-been-committed-tp5710573p5711663.html
Sent from the Struts - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: getOutputStream() has already been called for this response

2012-09-12 Thread raghu88
now this problem is solved i added a piece of code the file is
downloading when downloading the file it gives an exception cannot forward
after response has been committed .and
 i am trying to open the file it says
 the file you are trying to open .xls is in a different format than
specified by the file extension
how can i solve this issue pls help me.

 i edit my previous post and code pls see it 



--
View this message in context: 
http://struts.1045723.n5.nabble.com/Cannot-forward-after-response-has-been-committed-tp5710573p5710619.html
Sent from the Struts - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: getOutputStream() has already been called for this response

2012-09-06 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

raghu88,

On 9/4/12 2:25 AM, raghu88 wrote:
 i am trying to export some data to excel file...while doing this i
 am getting following exception:


 Servlet.service() for servlet action threw exception: 
 java.lang.IllegalStateException: getOutputStream() has already been
 called for this response at
 org.apache.catalina.connector.Response.getWriter(Response.java:598)

 
[:6.1.0.Final]

Why are you calling response.getWriter() when you want to export
Microsoft Excel (binary) data?

You want to be using getOutputStream anyway, so you should switch.

The problem is that getOutputStream has been called already for this
response, and so you can't use a Writer to generate a response instead.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBIyckACgkQ9CaO5/Lv0PCWdQCeOha4wFSe4opK3d00FLJ6GK7V
nqAAn3M0OZuC2G0yZdG4T4R1vWZ4C4mU
=o8DH
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: getOutputStream() has already been called for this response

2012-09-05 Thread Martin Gainty

Imagine you are the connector-code

Someone has called getOutputStream to write (some Thread Local data) to your 
HttpServletResponse object
then the call to getOutputStream (to the same thread) of HttpServletResponse is 
called AGAIN
Which OutputStream is the connector supposed to write (its Thread Local Data) 
to HttpServletResponse?

Martin 
__ 
Verzicht und Vertraulichkeitanmerkung

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.




 Date: Mon, 3 Sep 2012 23:25:40 -0700
 From: tammi...@gmail.com
 To: user@struts.apache.org
 Subject: getOutputStream() has already been called for this response
 
 hi to all,
 please any one help me .i am trying to export some data to excel
 file...while doing this i am getting following exceptionrecently i was
 done clustering with jboss and apache...then onwards i am getting  this
 error
 
 Here is the stack trace...
 
 Servlet.service() for servlet action threw exception:
 java.lang.IllegalStateException: getOutputStream() has already been called
 for this response
   at org.apache.catalina.connector.Response.getWriter(Response.java:598)
 [:6.1.0.Final]
   at
 org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:199)
 [:6.1.0.Final]
   at 
 org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
 [:6.1.0.Final]
   at
 org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
 [:6.1.0.Final]
   at
 org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
 [:6.1.0.Final]
   at
 org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:117)
 [:6.1.0.Final]
   at
 org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)
 [:6.1.0.Final]
   at
 org.apache.jsp.pages.MozartCostLoginAdmin_jsp._jspService(MozartCostLoginAdmin_jsp.java:86)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 [:6.1.0.Final]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 [:1.0.0.Final]
   at
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
 [:6.1.0.Final]
   at 
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
 [:6.1.0.Final]
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
 [:6.1.0.Final]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 [:1.0.0.Final]
   at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:734)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:541)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:479)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407)
 [:6.1.0.Final]
   at
 org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
 [:1.2.7]
   at
 org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
 [:1.2.7]
   at
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
 [:1.2.7]
   at 
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
 [:1.2.7]
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 [:1.2.7]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
 [:1.0.0.Final]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 [:1.0.0.Final]
   at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
 [:6.1.0.Final]
   at
 com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67)
 [:]
   at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
 [:6.1.0.Final]
   at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
 [:6.1.0.Final]
   at
 

Re: getOutputStream() has already been called for this response

2011-08-20 Thread Dave Newton
A request can only return one response: the file, or a forward (assuming
it's not some sort of streaming forward).

That method is pretty hard to follow, and should be refactored, IMO.

Dave

On Saturday, August 20, 2011, raaja.g raaj...@gmail.com wrote:
 Hi,

 I am getting the *java.lang.IllegalStateException: getOutputStream()* has
 already been called for this response when I use *return
 map.findForward(success)* at the end of action method. But this
exception
 wont appear if I return null. As I am not using writer object. But this
will
 not display an error message in the jsp through action messages.

 I am using struts1.3.

 How to avoid the above said exception so that I can generate a pdf when
 success and print a message when failed. As this is occurring because both
 writer and outputstream are using at the same time.

 Is it possible to close the outputstream after generating the pdf and
after
 that to send the message struts jsp using default writer.

 My code is:

 public ActionForward execute(ActionMapping map, ActionForm form,
HttpServletRequest req, HttpServletResponse res)
throws Exception {
String savefilename =
req.getParameter(savefilename)+.pdf;
FileForm file2 = (FileForm) form;
ArrayList list = file2.getList();
FormFile f2 = (FormFile) list.get(0);
Boolean b1 = validate(f2.getFileName());
if(b1==false){
ActionMessages messages = new ActionMessages();
messages.add(sts, new
 ActionMessage(common.generatepdf.onlyimages));
saveErrors(req, messages);
return map.findForward(success);
}
ServletOutputStream outStream=null;
Document document=new Document(PageSize.A4,0,0,10,10);
res.setContentType(application/pdf);
res.setHeader(Content-Disposition,attachment;
filename=+savefilename);
outStream = res.getOutputStream();
PdfWriter writer =
PdfWriter.getInstance(document,res.getOutputStream());
writer.setStrictImageSequence(true);
document.addHeader(String,Content);
document.open();
try{
for (int count = 0; count  list.size(); count++) {
FormFile f1 = (FormFile) list.get(count);
Boolean b = validate(f1.getFileName());
if(b==true){
Image convertJpg =
Image.getInstance(f1.getFileData());
if(convertJpg.getDpiX()75 
convertJpg.getDpiY()75){
convertJpg.scaleToFit(200, 200);
}
document.add(new Paragraph());
document.add(convertJpg);
}
}
document.close();
writer.close();
ActionMessages messages = new ActionMessages();
messages.add(sts, new
ActionMessage(common.generatepdf.success));
saveMessages(req, messages);
}catch(Exception e){
ActionMessages messages = new ActionMessages();
messages.add(sts, new
ActionMessage(common.generatepdf.fail));
saveErrors(req, messages);
}
finally {
  if(outStream != null)
try {
document.close();
writer.close();
outStream.close();
outStream.flush();
catch (IOException e) {
e.printStackTrace();

}
}

 */stack trace is:/*

 java.lang.IllegalStateException: getOutputStream() has already been called
 for this response
at
org.apache.catalina.connector.Response.getWriter(Response.java:611)
at

org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at

javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:122)
at
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:187)
at

org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:180)
at

org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:237)
at

org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:173)
at

org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:124)
at

org.apache.jsp.pages.common.GeneratePdf_jsp._jspService(org.apache.jsp.pages.common.GeneratePdf_jsp:256)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at 

Re: getOutputStream() has already been called for this response

2008-12-10 Thread Dave Newton
When you return SUCCESS you're asking S2 to process the response normally. I'd 
assume you'd need to return null to indicate that S2 shouldn't do anything.

I don't actually know if that works, because there's a stream result type 
designed specifically for this situation.

Dave


--- On Wed, 12/10/08, red phoenix [EMAIL PROTECTED] wrote:

 From: red phoenix [EMAIL PROTECTED]
 Subject: getOutputStream() has already been called for this response
 To: Struts Users Mailing List user@struts.apache.org
 Date: Wednesday, December 10, 2008, 11:26 AM
 I use struts2.0.11,I want to show a picture by struts
 action,like follows:
 public String showphoto() throws Exception{
 response=ServletActionContext.getResponse();
 response.setContentType(image/png);
 ...
 InputStream in = picture.getBinaryStream();
 OutputStream out = response.getOutputStream();
 byte[] buf = new byte[1024];
 int len;
 while ((len = in.read(buf)) != -1){
  out.write(buf, 0, len);
 }
 in.close();
 out.close();
 response.flushBuffer();
 return SUCCESS;
  }
 
 When I run above code,it can run well,and it can show
 picture in jsp,but I
 find it write error information in tomcat6,like follows:
 fatal: Servlet.service() for servlet jsp threw exception
 java.lang.IllegalStateException: getOutputStream() has
 already been called
 for this response
  at
 org.apache.catalina.connector.Response.getWriter(Response.java:610)
  at
 org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
  at
 javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
  at
 org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
 
 Why raise above error in tomcat6? How to correct my code to
 correct above
 error?
 Thanks in advance!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]