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.
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Generate an HTML Response in a Java Servlet
(3 answers)
Closed 3 days ago.
I've been getting a good understanding of raw servlets, now, I know that HTML is prebuilt so if the client wanted to make a request to the server for some type of dynamic change, is this where i need to use JavaScript to make that request and do some DOM minuplulations?
Help me understand JSP, so instead of doing that DOM minuplulations with javascript from the client, I can just use JSP on the server and have my servlets build the page on run time then return that jsp back to the client?
Help me undertstand JSP vs HTML on how they differ from client to server
now i know if i make a request to the server for a page it comes back as a html that ive built, to populate the page with data from the server i would need to make request using js then use the response data to make sometype of changes within the clientside, so is this where JSP comes in handy, the work will be done on the server side? all the server got to do is insert the data and return the page?
This question already has answers here:
How can I upload files to a server using JSP/Servlet?
(14 answers)
Closed 6 years ago.
I receive a request (multipart/form-data POST), parameter "file" contains file as a base64 (example below)
------WebKitFormBoundaryEA37wQGzpnprPt8x\r\nContent-Disposition: form-data;
name=\"file\"\r\n\r\nJVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvQXV0aG9yIChNYXJrbyBLZWpcMjM2YXIpL0Ny\r\nZWF0aW9uRGF0ZSAoRDoyMDE2MTEyMjExMzc0NCswMScwMCcpL0NyZWF0b3IgKE1TIFdvcmQg\r\nRG9jdW1lbnQ
I am curious how to decode it (using JAVA of course) from there and get a file.
Should I somehow delete system information (WebKitFormBoundary and Content-Disposition)?
I also noticed that content full of \r\n Do I need to delete it myself as well?
you can use following link to decode from base64
https://www.base64decode.org/
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-269016b5c31c942c/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-269016b5c31c942c/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.)
I've been meaning to do this for a long time. I want my user to save/update a text file to an online server. How can I connect to my server, and then to a certain file;
In php and other languages, you must include a connect.php file, which contains your sql table name, username, pswrd, and hostname.
Is there such a set up in a function to write in your Java code? Can you post some code answers on how you login and then, update a .txt file?
you want to save a file, so why connect via database?
In Java, you can do the same thing using JSP. In your JSP, accept input (via HTTP Request object) and save the data to file.
To save a file, I suggest you use Apache Commons FileUtils rather than writing your own code.
Use FileUtils.writeStringToFile method(File, String, Charset)
http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#writeStringToFile(java.io.File, java.lang.String, java.nio.charset.Charset)
I'm wondering if there is any way to upload files from a java program to a website that has a simple html form.
An example could look like the one on tinypic.com or bayimg.com.
Are there any Java libraries capable of performing this? Please point me in the right direction :).
Thanks.
Mike.
HTML Form uses just HTTP POST/PUT methods to upload file to server, you don't have to work/think in this case with HTML FORM, just do HTTP Connection to script and send data in required format
Read more:
http://www.jguru.com/faq/view.jsp?EID=62798
http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload
http://www.java-tips.org/other-api-tips/httpclient/how-to-use-multipart-post-method-for-uploading.html
http://www.prasannatech.net/2009/03/java-http-post-file-upload-server.html
http://www.google.cz/search?aq=f&sourceid=chrome&ie=UTF-8&q=java+http+post+upload