This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Setting content Type in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Setting content Type in JSP" Watch "Setting content Type in JSP" New topic
Author

Setting content Type in JSP

Nitin Kumar
Greenhorn

Joined: Apr 18, 2005
Posts: 29
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

Joined: Mar 17, 2001
Posts: 213
Hey,
I have got both the above code working fine. It ask File Dialog window to either save or open
Regards


Sarath Mohan
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nitin Kumar
Greenhorn

Joined: Apr 18, 2005
Posts: 29
Thanks....
Its working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting content Type in JSP
 
Similar Threads
Export to excel
how to extract data to an xl sheet
How to Open Excel file from JSP page.
Using response.setContentType to switch HTML to Word
HTML table to an Excel Spreadsheet