-1

I'm newbie to Java and I have create simple HTML form for files upload (All type of file). I want to upload the file to directly to my server.

My URL is http://www.example.com

My html code is

<html>
    <head></head>
    <body>
        <form  name="data" action="" method="post">
            <div id="formName">
                <label>Pancard:</label><br />
                <input type="file" name="pancard"  id="pancard" class="required">
                <input type="submit" value="Submit Details" name="Submit" >
            </div>
        </form>
    </body>
</html>

How to upload and save the uploaded file in server (in my url) using Java at the backend.

I need to store the all upload file in server and i download the file from server directly.

I don't want to store in local or temp file. When i upload the file and save it in my server (example URL)...

How to save or upload the file direct to server(URL)

MWiesner
  • 8,868
  • 11
  • 36
  • 70
sakthi
  • 65
  • 1
  • 1
  • 11
  • Welcome to SO. Please visit the [help] to see what and how to ask. HINT: Show effort and code. Not just a form. There are answers to your questions all over the net and SO – mplungjan Oct 20 '16 at 11:27
  • Have you searched your title on Google? – Pradeep Simha Oct 20 '16 at 11:28
  • Possible duplicate of [How to upload files to server using JSP/Servlet?](http://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet) – mplungjan Oct 20 '16 at 11:29
  • @mplugjan i try some code but i need to store upload file in my url(server)... – sakthi Oct 20 '16 at 11:47
  • Yes - you need a java server process or are you confusing JAVA the server programming language with JavaScript the client scripting language? They are NOT the same. – mplungjan Oct 20 '16 at 11:49
  • @mplungjan i try some java servalet sample program and upload file store in my tmp directory.http://www.journaldev.com/1964/servlet-upload-file-download-example#comment-36630 i tried this sample code and i dont know where put my url for store the uploaded image – sakthi Oct 20 '16 at 11:52
  • http://stackoverflow.com/questions/1342506/why-is-form-enctype-multipart-form-data-required-when-uploading-a-file – mplungjan Oct 20 '16 at 11:59

1 Answers1

0

For file upload, the form should be use enctype="multipart/form-data"

<form action="" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input id="fileToUpload" type="file" name="fileToUpload">
    <input type="submit" name="submit" value="Upload Image">
</form>

In your java, you should get the file and define the location to store the image. I find below two links are similar to your questions, you can try.

Hope this help!

Community
  • 1
  • 1
Donald Wu
  • 698
  • 7
  • 20
  • i don't know where i define the my server url in my code. i use the sample code from this site journaldev.com/1964/servlet-upload-file-download-example – sakthi Oct 24 '16 at 06:22
  • After submit button click, you can set the form ``action`` to your java. 1. Define a controller, set a route, the form action goes to the route. Write the logic in Model, then call the model in controller.........2. Use Servlet, after submit button click, form action goes to the servlet. – Donald Wu Oct 24 '16 at 14:30