download file from html page not working [duplicate] - java

This question already has answers here:
Recommended way to save uploaded files in a servlet application
(2 answers)
Closed 7 years ago.
I uploaded new app on Jboss 7.
That app, amoung other things, can create file, save it and hopfully download it with html5 tag.
After generated, the file saves on absolute path that I get from
getServletContext().getRealPath("/");
By the server log I can tell that those actions done perfectly.
The file is created and saved.
The problem is with the download part.
I am trying to download the file with html5 tag.
<a href=path+file name> download>Get Numbers!</a>
I am using exactly the same path that I used to save the file on the server and I keep getting that fail-no file error from Chrome.
Ideas?

I am using exactly the same path that I used to save the file on the server
There's the problem. Your file path is something like this:
/opt/repo/versions/7.1/standalone/tmp/vfs/tempc56e386fb58c08a8/SlL.war-269‌​016b5c31c942c/serial.xls
That's fine on the server when getting the file from the file system. But that path means nothing to a web browser. The web browser is making a request to the web server for a file known to the web server.
So, for example, if your web server root is here:
/opt/mywebserver
Then that path ends up requesting this:
/opt/webserver/opt/repo/versions/7.1/standalone/tmp/vfs/tempc56e386fb58c08a8/SlL.war-269‌​016b5c31c942c/serial.xls
That file doesn't exist, so the web server responds with a 404 error.
You need to convert the file system path to a URL in order to use it in the markup. (And that path needs to be publicly visible to the web server, within its own path structure.)

Related

how list all files from directory in java web application?

I implemented a java web application using html page and servlet classes. In servlet class, I need to read a list of files one by one from a specific directory in the project as follows:
File folder = new File("C:\\Users\\Alahram\\Desktop\\latest RC2\\latest
RC2\\RC2\\src\\docs\\");
File[] files = folder.listFiles();
It works correctly from an absolute path on localhost, but I need to use relative path for this directory to be able upload this project to the server. Can anyone help me in this problem?
The application container (Tomcat, Jetty or any other) started on a specific host cannot access to filesystem of the client of a distinct host that uses it through its browser for obvious physical (a machine don't see the filesystem of the other by default : these are not connected) and security reasons (we would not that either).
To be able to load this directory you should zip it from the client side and then send it via a HTTP request, what we commonly call upload. Then unzip it from the server side.

Oauth identity toolkit

I am at last step to configure the identity tool kit login authentication , so they talk about configure server side " There are two code snippets at the bottom of the page. The first snippet helps make the JavaScript configuration easy for your website. The second snippet should be saved in your server side code directory as gitkit-server-config.json.
The server side configuration file needs to be further configured before use. Open the file for editing and change serviceAccountPrivateKeyFile setting to be equal to the path of the *.p12 or *.json file you downloaded earlier. You should use the full path, beginning with / and ending with the full name of the *.p12 or *.json file" can any one help me

How to upload and download a file with the given path(already known) without using html form in servlet using post method?

I know solution of the above problem using HTML form in which user chooses a file from computer and upload it and then download it but how to do it without using HTML with the already given path of file.
Thank you For your concern in Advance.
I assume the scenario is that the user accesses your server from a browser.
In this case you will not be able to access the file system given file paths. Only the user can grant access to certain files by selecting them in a file upload input.
If the user uses a mobile/desktop application that sends the file to your server, you must implement the upload in the app itself.

Upload CSV file to servlet then pass it to java program [duplicate]

This question already has answers here:
How can I upload files to a server using JSP/Servlet?
(14 answers)
Closed 9 years ago.
I have written a stand along java program that loads a CSV file with addresses line by line and geocodes them using an API. I have now been given the task of making this program run off a server. I have no experience dealing with servers. Basically what I need to do is the following,
1. Upload the CSV file to the server via a servlet
2. Pass in the file location as a String parameter into my java code via a function call.
Any help would be much appreciated. Thank you.
You basically need to write a servlet to handle a POST request to upload the file. The message body of POST can be of multipart/form type to contain both the path of the file and actualy bytes of the file. Just extract this information from the incoming request in servlet and do the processing as you need.
You may explore Apache Commons Fileupload for doing the same.

how to access directory from file server in java?

HI...
Currently I m working in a application in which application allows to access directory (which contains some files) from file server to Application (client).
I tried following code..
URL url=("http://192.168.5.555/file-server/user/images/");
URI uri=url.toURI();
File list[];
list= new File(uri).listFiles();
But its thrown java.lang.IllegalArgumentException Exception.
I don't know how this happen?
I simply access images directory from the given URL (file server).
Help me...
That isn't going to work. The java.io.File operates on the local disk file system only, i.e. on URI's starting with file:// only. It would otherwise indeed going to be too easy to leech files from places where you aren't allowed to do so.
Check if the server in question supports FTP, then you can just use FTPClient#listFiles() for this. If it doesn't, but it supports directory listing, then you need to parse the HTML response containing the directory listing with a HTML parser like Jsoup and then refire a new request on every found link.
If it doesn't support FTP or directory listing, then you're lost and you're probably trying to do bad things.

Categories