Click to See Complete Forum and Search --> : JSP to RTF renders as text


kmonroe6
07-13-2005, 09:16 AM
Hello!

I'm trying to use JSP to send content in RTF format and have it opened automatically by MS Word. The content I'm sending opens in Word as text, not as rendered RTF. My JSP page has the following:

<%@ page contentType="application/rtf;charset=utf-8" %>
<% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" ); %>
RTF content here

I've also tried contentType="text/rtf" with the same results. I've used this same code to go directly to Word using just:
<% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.doc" ); %>

Ideas??

Thx

Mongus
07-13-2005, 08:07 PM
Are you sure you're sending valid RTF?

With the JSP you posted you'll have two blank lines before any RTF. I don't know the file format for RTF so I can't say if that is valid. Try making sure there's no whitespace in your output.

I usually format my JSP pages like this to remove whitespace:

<%@ page contentType="application/rtf;charset=utf-8"
%><% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" );
%>RTF content here

kmonroe6
07-18-2005, 08:15 AM
The whitespace is exactly the problem! I've got the following code:

<c:when test="${not empty param.prntLetter}">
<%@ page contentType="application/rtf;charset=utf-8"
%><% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" );
%>{\rtf1\ansi\ansicpg1252\uc1\deff0\sts...
</c:when>

I keep getting a bunch of blank lines at the start of the RTF and I can't figure out how to get rid of them.

Thx

Mongus
07-18-2005, 02:46 PM
You've got to remove all whitespace between tags. If you use a "<%@ include file=" you'll want to switch to "<c:import url=" because the include directive always inserts a CRLF. :(

The code you just posted should look more like this:

<c:when test="${not empty param.prntLetter}"
><%@ page contentType="application/rtf;charset=utf-8"
%><% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" );
%>{\rtf1\ansi\ansicpg1252\uc1\deff0\sts...</c:when>