Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Have Struts forward to a servlet?

Thread view: 
richardsosborn@gmail.com - 19 Oct 2005 20:48 GMT
We have a situation where we need to create a XLS file from a web
application.
The only way we could come up to create the file and have it DL to the
browser
was by forwarding to a servlet.  Then the servlet would create the file
and send it to the client.  The XLS file would be mapped as a MIME type
in the web.xml.
Problem is, can struts forward to a servlet?  If so, what would the
line look like?

<forward name="excel_file" path="/reports/my_servlet"/>
Babu Kalakrishnan - 20 Oct 2005 04:56 GMT
> We have a situation where we need to create a XLS file from a web
> application.
[quoted text clipped - 7 lines]
>
> <forward name="excel_file" path="/reports/my_servlet"/>

Have you tried streaming the output directly to the OutputStream
obtained from the response object (instead of using another servlet) ?

I've had success with something on the lines of :

response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition",
"attachment;filename=\"filename.xls\"");
OutputStream out = response.getOutputStream();
response.setContentLength(data.length);
out.write(data);
out.flush();
out.close();

(Assuming that the content to be output is in a byte[] called "data").

Also make sure you return null as the ActionForward from your Action's
execute method so that Struts doesn't try to send out something more to
the response which has already been committed,

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.