/    Sign up×
Community /Pin to ProfileBookmark

JSP to RTF renders as text

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

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@MongusJul 14.2005 — 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:
<i>
</i>&lt;%@ page contentType="application/rtf;charset=utf-8"
%&gt;&lt;% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" );
%&gt;RTF content here
Copy linkTweet thisAlerts:
@kmonroe6authorJul 18.2005 — 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" );

%>{rtf1ansiansicpg1252uc1deff0sts...

</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
Copy linkTweet thisAlerts:
@MongusJul 18.2005 — 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:
<i>
</i>&lt;c:when test="${not empty param.prntLetter}"
<i>&gt;</i>&lt;%@ page contentType="application/rtf;charset=utf-8"
%&gt;&lt;% response.setHeader("Content-Disposition","attachment; filename=" + "Letter.rtf" );
%&gt;{rtf1ansiansicpg1252uc1deff0sts...&lt;/c:when&gt;
×

Success!

Help @kmonroe6 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...