hi all,
i have a problem when i click the link in jsp page. whenever i am clicking the jsp page link it wants to open a pdf file, the pdf file is located in remote system. its working properly in Internet Explorer. but i am opning this in FireFox means its not opening. In firefox url that is not showing the exact path. optionally its showing like that:


journal/%5C%5C%5C
copyediting%5CELS%5C
Manuscript_Screening%5CMS%5C
RDTEST%5C02-Process%5C
RDTEST-D-08-02051.fdf

and my jsp code whichever working fine in Internet Explorer is :

<%

String newpath="\\\\\\copyediting
\\ELS
\\Manuscript_Screening\\MS\\RDTEST\\
02-Process\\RDTEST-D-08-02051.fdf";

%>

<a href="<%=newpath%>" target="dynamic"></a>

can any one solve my problem. as soon as possible. thanks in advance.

Dani AI

Generated

Short summary: Firefox is refusing the raw Windows/UNC path and shows percent-encoded backslashes (%5C); IE historically let such links reach the local file handler, so it worked there. ‘s client-side fix (installing Policy Manager and FoxyProxy) changes Firefox behavior on that machine, but it’s a workstation-specific workaround and not a good long-term or cross-browser solution.

Why it fails and the robust fix: browsers expect HTTP(S) URLs with forward slashes. Linking to a network share from a web page is blocked or encoded by modern browsers for security. The reliable, cross-browser approach is to let the web server deliver the PDF: have the server read the file (from local disk or a network share it can access) and stream it with the correct MIME type and disposition headers. As suggested, set Content-Type to application/pdf and Content-Disposition to inline (or attachment) and write the bytes to the response.

Example (server-side streaming servlet pattern):

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    File pdf = new File("\\\\server\\share\\docs\\file.pdf"); // server-side UNC access
    resp.setContentType("application/pdf");
    resp.setHeader("Content-Disposition", "inline; filename=\"file.pdf\"");
    try (InputStream in = new FileInputStream(pdf);
         OutputStream out = resp.getOutputStream()) {
        byte[] buf = new byte[8192];
        int len;
        while ((len = in.read(buf)) != -1) out.write(buf, 0, len);
    }
}

For a linked image that opens the PDF, point the anchor at the download endpoint (the servlet) and wrap the icon:

<a href="/download?file=file.pdf"><img src="/images/pdf-icon.png" alt="PDF"></a>

Notes and cautions: ensure the web process account has read access to the network share if the server reads UNC paths. Avoid relying on client-side extensions or local configuration for public-facing apps; server-side streaming gives consistent behavior across Firefox, IE/Edge, Chrome and mobile browsers. As requested, posting a server-side approach preserves a stable solution others can reuse.

Recommended Answers

All 6 Replies

Set the Content-type and content-disposition headers and send the bytes through exactly as you read them.

Edit: nevermind that. Set your file/program associations in FireFox.

hi all,

i got the solution for this question. thanks for ur replies.

Would be nice if you can post your solution as it may help somebody in the future.
Also please mark this post as solved.

how to open pdf files in jsp page?

how to link pdf file with a picture?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.