I have a question which is both a best practice and priorty question.
I have a simple
jsp which will show output in one of three formats:
html,
word, or excel.
When I use index.jsp outputs html, when I use index.jsp?format=word outputs as a word document on Internet explorer.
My question is what takes priorty, the response.setContentType or the
<head>
<meta http-equiv="Content-type" content="text/html" ...
the answer must be the response.setContentType but the answer isn't obvious to me.
Can anyone tell me how one should set up the response.setContentType("text/html") or ("application/msword").
That is, is there a semi-standard for dealing with this issue or position in the jsp file where
you should put switches over content type?
Thank you,
----------------------------- code below ------------------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My Response Type
Test</title>
</head>
<%
if (request.getParameter("format") != null) {
if (request.getParameter("format").equals("word")) {
response.setContentType("application/msword");
} else if (request.getParameter("format").equals("excel")) {
response.setContentType("application/vnd.ms-excel");
}
}
%>
<body>
<h2>Testing Word Document Format</h2>
<table border="1">
<tr>
<th>Team</th><th>QuarterBack</th><th># Super Bowls</th><th>Rating</th>
</tr>
<tr>
<td>49ners</td><td>Joe Montana</td><td>4</td><td># 1</td>
</tr>
<tr>
<td>Patriots</td><td>Tom Brady</td><td>3</td><td># 2</td>
</tr>
<tr>
<td>Steelers</td><td>Terry Bradshaw</td><td>4</td><td># 3</td>
</tr>
<tr>
<td>Broncos</td><td>John Elway</td><td>2</td><td># 4</td>
</tr>
</table>
</body>
</html>