• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to write a byte[] from a JSP page.

 
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP and I tried adding this into it ..
and I get Illegal Argumentat error . but I cant see any way in JSP of writing out a byte array. IF I try the simple ..



out IT doesnt have the write method to write bytes .. How can I write the byte[] in JSP.


Thanks
Dhiren

[ June 27, 2005: Message edited by: Dhiren Joshi ]
[ June 27, 2005: Message edited by: Dhiren Joshi ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is in the byte stream contained in scoped variable "reports"? Unless it's HTML or plain text, a JSP is most likely not the best mechanism for delivering it.
 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a Pdf output.
Since I am using Struts I am not sure I can forward from action classes without a JSP to display it.
IF it helps this is my action class in Struts.



I dont know how to write the output unless I send it to JSP using Struts action classes
Thanks
Dhiren
[ June 27, 2005: Message edited by: Dhiren Joshi ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need for a JSP at all, you should be emitting such output directly. A JSP will just get in the way.

I'm moving this to the Struts forum so that the Struts-savyy can instruct you on how to best emit binary output from a Struts action.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not even create a jsp for this. Here is how:

In the Action class, get the output stream from the response object. Write your file to the stream and flush it.

Don't forget to set the header:
response.setHeader("Content-disposition","attachment; filename=myPDF.pdf");
Replace "attachment" with "inline" if you wish to display the content in the already-open browser window.

Best of luck!
 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marc for the reply.
What happens to the .forward(requestType) ...

Dont I need to forward this to any file at all.
How will the action class work without a forward call. Not sur eas I dont have enough Struts expertise.

Thanks
Dhiren
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No forward is needed.

The output stream is basically what gets sent back to the browser and you will be placing the file in the output stream byte by byte. When the output stream is flushed, it becomes the response sent to the user. Give it a try. It's not very difficult and seeing it work will clear up any doubt.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you just return null from the execute() method in your action class, Struts assumes the action class is providing the response, and will not try to forward to a JSP.

Also, there is an example of writing to the output stream in the struts-examples.war file that comes with the struts 1.2 download. Check out org.apache.struts.webapp.exercise.ImageAction.
[ June 28, 2005: Message edited by: Merrill Higginson ]
 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for all the prompt replies in helping me out.
Thanks
Dhiren
 
reply
    Bookmark Topic Watch Topic
  • New Topic