• 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

URL Rewrite for different output formats

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This faq entry has an example:
http://faq.javaranch.com/view?JspAndExcel
 
reply
    Bookmark Topic Watch Topic
  • New Topic