It is possible to determine the access path to the file in Function

Asked

Viewed 328 times

6

I have a Java WEB application where I am using a Function that opens the file .pdf which I determine, but it only opens the files .pdf that are in the same folder where this saved my project, already tried to change my variable String that calls the file .pdf and put the Access path, for example, "C: test.pdf" however it never finds the file if I put the path together, it is possible to change the access path of the files?

<%
        String arquivo = "";
        String i = "";

        try {
            if (request.getParameter("nomeArq").contains("null")){
                arquivo = request.getAttribute("nomeArquivo").toString();
            }else{
                arquivo = request.getParameter("nomeArq");
            }
        } catch (Exception e) {
            arquivo = request.getAttribute("nomeArquivo").toString();
        }
        try {
            i = request.getParameter("numeroPag").toString();
        } catch (Exception a) {
            i = request.getAttribute("pagina").toString();
        }


    %>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            window.onload = function abrirPdf() {
                var iframe = $("#LoteSlips");
                iframe.attr("src", '<%=arquivo%>_ERRO.pdf#zoom=200&page=<%=i%>'); 
            };
        });
    </script>
  • 1

    java? The code looks more like jquery

  • 1

    For that you would have to use the file:// src and run Chrome (for example) through cmd passing as parameter the --allow-file-access-from-files. The browser for security reasons does not allow access to the files on the client’s machine.

  • Unless the application works only locally (and it still makes little sense), it makes no sense what you want, otherwise use the absolute path using the protocol http or the relative path to the file based on the directory where the script is located.

  • @Filipemoraes Would you be able to give me an example of how to do this and where I would make these changes? Because what I need is to be able to change in funtion the directory where my *.pdf files are without having to be saved along with the project.

  • Is your application just to work locally? Do you have PHP installed locally? How is your environment at the moment?

  • At the moment I have a jsp page that creates a table with the name of the files. pdf that are in the directory "C: test", for example, from there when I click on open the command for this page to view the pdf the name of the selected file, but as I can not change the path in Function "C: test_arq_pdf" I need to save the files also along with my project, I will edit the question to show how this my page view pdf

  • Are you using Struts? which version?

  • @Davidschrammel Struts?

Show 3 more comments

1 answer

3


You bumped into a security issue. By default browsers do not allow web applications to access local files without the user’s permission. What is right, imagine you accessing any site, and while you browse the site picks up several files from your computer. Nothing good is not?

An alternative is you upload the file, process it on the server and return the result to the client. I don’t know if that solves your problem, but that’s what can be done.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.