Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting content Type in JSP

 
Nitin Kumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Tomcat5.5.9 installed in my computer. I am trying to set content type using Scriplet and Page directive as mentioned below. None of then works

Using Scriplet :

<% response.setContentType("application/vnd.ms-excel"); %>
<HTML>
<BODY>
<TABLE BORDER =2>
<TR><TH>first<TH>Last
<TR><TD>abc <TD>xyz
<TR><TD>mno <TD>qrs
</TABLE>

</BODY>
</HTML>

2 using page directive

<%@ page contentType = "application/vnd.ms-excel" %>
<HTML>
<BODY>
<TABLE BORDER =2>
<TR><TH>First<TH>Last
<TR><TD>abc <TD>xyz
<TR><TD>mno <TD>qrs
</TABLE>

</BODY>
</HTML>



But following code works fine

<HTML>
<BODY>
<% String format=request.getParameter("format");
if (format!=null && "Excel".equals(format))
response.setContentType("application/vnd.ms-excel"); %>

<TABLE BORDER =2>
<TR><TH>First<TH>Last
<TR><TD>abc <TD>xyz
<TR><TD>mno <TD>qrs
</TABLE>

</BODY>
</HTML>

whats going wron here ?
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I have got both the above code working fine. It ask File Dialog window to either save or open
Regards
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know it's not working?
Do you have a tool such as LiveHTTPHeaders that allows you to see the response headers?

You may be setting them correctly but still not seeing the desired results.
What are you trying to do? What results are you getting and what were you expecting?
 
Nitin Kumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks....
Its working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic