File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes URL Rewrite for different output formats Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "URL Rewrite for different output formats" Watch "URL Rewrite for different output formats" New topic
Author

URL Rewrite for different output formats

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

Hi All,

I have a servlet that can return data in multiple output formats including pdf, excel, html. Generating the files and setting the content works fine, but I'd like to rewrite the request URL (if possible) for a more standard output. For example, if the user requests "print.jsp", I would like the URL rewritten to "print.pdf" for PDF and "print.xls" for Excel files, so that when a user goes to save the files, that is the name they get automatically. Currently if they go to save, they get print.jsp. Also, my browser is finicky and without the ".xls" it just wants to save Excel files to disk instead of open in the browser (even though content type is set to excel).

Is rewriting the request URL possible or does it require (trying to avoid) a redirect?

Also, I'm currently using an event-based architecture with forwarding built in, but it doesn't seem to work, in particular I'm using:



Where print.pdf is the name of the PDF I want to rewrite the URL to. This type of forwarding does not seem to change the URL value though.
[ July 05, 2007: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Scott,
Have you tried setting the Content-Disposition header?
This header allows you to specify the saved file's name as well as suggest whether the browser should display the file with the associated application in line or promp the user with a save/open dialog box.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This faq entry has an example:
http://faq.javaranch.com/view?JspAndExcel
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: URL Rewrite for different output formats
 
Similar Threads
Generate PDF report from jsp
How to output HSSF excel data in browser?
Export to Excel via a servlet with POI not working under internet explorer 6
Export to Excel not working with Internet Explorer HSSF and POI
Cannot open PDF directly, save works