Unable to open .chm file from a link in Weblogic .

Discussions

General J2EE: Unable to open .chm file from a link in Weblogic .

  1. Unable to open .chm file from a link in weblogic server. But the same jsp code works in Websphere

    Sample Code :


    <!-- < a href="JavaScript:window.navigate('help/ARTGALRY.CHM')"> Linked Text</a> -->



    The above link, works well in websphere. help is a folder that resides in the server. But when i tried to execute the same in Weblogic, some junk characters appeared . so i tried to direct the link to Display.jsp and passed the path of the chm file as the parameter. I cleared teh out buffer using out.clearBuffer() . i set the content type to application/x-msdownload and also set the header to content disposition.

    Nothing worked .

     I need immediate help to sort out this issue. Can anybody help me
    <br>

    Thanks in advance
    Sumithra
  2. Hi,
    I think you should check your server configurations on how to associate file extensions to mime types. From what you are telling I suppose websphere has the
    *.chm -- application/x-msdownload mime type associtation, while weblogic doesn't.
    Best regards, Mircea
  3. Hi
      Thanks for your reply. I even tried including the mime type
    <mime-mapping>
        <extension>chm</extension>
        <mime-type>application/x-msdownload</mime-type>
      </mime-mapping>

    in the web.xml file. and still it doesnt work. What should i do ?
  4. Hi
    Another solution would be to write a servlet mapped on the '*.chm' requests that sets the appropriate content type ("application/x-msdownload") and writes the bytes in the output stream.
    Best regards, Mircea
  5. Hi
           I tried writing a Jsp, i checked if the file extension is .chm , then set the response.setContentType to " application/mshelp " (i even tried setting application/mshelp in web.xml adn provinding this in response.setContentType). I cleared the out object's buffer and got the OutputStream from the response object and tried getting the buffers everything. Still it doesnt work. Here is the code that i wrote.

    if(extension.equalsIgnoreCase(".chm")){
    response.setContentType("application/mshelp");
    }
    response.setHeader("Content-disposition", "attachment; filename="+fileName);


    ServletOutputStream out_s = null;
    BufferedOutputStream bos = null;
    InputStream fin = null;
    try {
    System.out.println("HII" + response.isCommitted() );
    URL url = new URL(finalPath);
    URLConnection conn = url.openConnection();
    System.out.println("get ContentType ====== "+conn.getContentType());
         fin = conn.getInputStream();
    //fin = new FileInputStream(finalPath);
    System.out.println("fin . available ==== "+fin.available());
    byte[] b = new byte[fin.available()];
    fin.read(b);
    out.clearBuffer();
    out_s = response.getOutputStream();
    System.out.println("committed = "+response.isCommitted());
    //out_s.println("Testing");
    bos = new BufferedOutputStream(out_s);
    bos.write(b);

    } catch (Exception e) {
    e.printStackTrace();
    }//end of catch
    finally {
    try {
    if (fin != null) {
    fin.close();
    }
    if (bos != null) {
    bos.close();
    }
    if (out_s != null) {
    out_s.flush();
    //out_s.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }//end of catch
    }//end of finally
  6. Hi
           I tried writing a Jsp, i checked if the file extension is .chm , then set the response.setContentType to " application/mshelp " (i even tried setting application/mshelp in web.xml adn provinding this in response.setContentType). I cleared the out object's buffer and got the OutputStream from the response object and tried getting the buffers everything. Still it doesnt work. Here is the code that i wrote.

            if(extension.equalsIgnoreCase(".chm")){
    response.setContentType("application/mshelp");
    }
    response.setHeader("Content-disposition", "attachment; filename="+fileName);


    ServletOutputStream out_s = null;
    BufferedOutputStream bos = null;
    InputStream fin = null;
    try {
    System.out.println("HII" + response.isCommitted() );
    URL url = new URL(finalPath);
    URLConnection conn = url.openConnection();
    System.out.println("get ContentType ====== "+conn.getContentType());
         fin = conn.getInputStream();
    //fin = new FileInputStream(finalPath);
    System.out.println("fin . available ==== "+fin.available());
    byte[] b = new byte[fin.available()];
    fin.read(b);
    out.clearBuffer();
    out_s = response.getOutputStream();
    System.out.println("committed = "+response.isCommitted());
    //out_s.println("Testing");
    bos = new BufferedOutputStream(out_s);
    bos.write(b);

    } catch (Exception e) {
    e.printStackTrace();
    }//end of catch
    finally {
    try {
    if (fin != null) {
    fin.close();
    }
    if (bos != null) {
    bos.close();
    }
    if (out_s != null) {
    out_s.flush();
    //out_s.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }//end of catch
    }//end of finally