• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Setting content Type in JSP

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks....
Its working.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic