Results 1 to 2 of 2
  1. #1
    JordanParfitt is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default contentType="application/vnd.ms-excel" Not Working

    I have a page with a grid on it that I want to export to excel. This has been working for quite some time (years) but the other day instead of opening in excel it has been opening in a browser window. Since the code is the same I am thinking it is a problem with a java or tomcat update. Does anyone know if there is a new code instead of: <%--@page contentType="application/vnd.ms-excel"--%>"?

    Here is the bulk of my code. Thanks in advance.

    -Jordan



    <%--@page contentType="application/vnd.ms-excel"--%>
    <jsp:useBean id="map" class="com.esri.aims.mtier.model.map.Map" scope="page" />
    <%@ page import="java.net.URLEncoder" %>
    <%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
    <%@ page import="javax.xml.parsers.DocumentBuilder" %>
    <%@ page import="com.esri.aims.mtier.model.map.layer.query. *" %>
    <%@ page import="org.w3c.dom.*" %>

    <%!
    private String formatURLString(String inputURL) {
    if (inputURL.indexOf("htt*p://")>-1 || inputURL.indexOf("htt*ps://")>-1 || inputURL.indexOf("ftp://")>-1) {
    return inputURL;
    } else if (inputURL.indexOf("ww*w.")==0) {
    return "htt*p://"+inputURL;
    } else {
    return "htt*p://"+inputURL;
    }
    }
    String cleanHeader(String h) {
    if (h.indexOf('.')>-1) {
    h=h.substring(h.lastIndexOf('.')+1,h.length());
    }
    return h;
    }
    %>
    <%@ include file="setupinc.jsp" %>
    <%
    if (session.getAttribute("ResultsExport") !=null && request.getParameter("doExport")!=null &&
    request.getParameter("doExport").equals("true")) {
    try {
    recordResult rr = (recordResult)session.getAttribute("ResultsExport" );
    if (rr.features!=null && rr.metadata!=null &&
    rr.features.length>0 && rr.metadata.fieldNames.length>0) {
    out.print("<table border=\"1\" cellspacing=\"0\" class=\"r\"><tr>");
    int i, j; // iterators
    String str;
    for (i=0; i<rr.metadata.fieldNames.length; i++) {
    str=cleanHeader(rr.metadata.fieldNames[i]);
    if (!str.equalsIgnoreCase("#shape#")) {
    out.print("<th>"+str+"</th>");
    }
    }
    out.print("</tr>");
    for (i=0; i<rr.features.length; i++) {
    out.println("<tr>");
    for (j=0; j<rr.features[i].values.length; j++) {
    if (!rr.metadata.fieldNames[j].equalsIgnoreCase("#shape#")) {
    out.println("<td>"+rr.features[i].values[j]+"</td>");
    }
    }
    out.println("</tr>");
    }
    out.print("</table>");
    } else {
    out.print("<table border=\"1\" cellspacing=\"0\" class=\"r\">");
    out.print("<tr><th>Null Issue</th></tr></table>");
    }
    } catch (Exception e) {
    out.print("Error: "+e);
    }
    }

    %>

  2. #2
    JordanParfitt is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default

    After research, adding "response.setContentType("application/vnd.ms-excel");" to the first line of code seems have taken care of the problem.

    Thanks!

    -Jordan

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 5
    Last Post: 01-27-2009, 03:49 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 10
    Last Post: 12-30-2008, 03:46 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •