JSP Tutorials - Herong's Tutorial Examples - Version 4.03, by Dr. Herong Yang
Test 1 - GET Method - Failed
This section provides a tutorial example of testing file upload with the HTTP GET method. The test failed, because file upload only works with the POST method, not the GET method.
Before looking the Part 4, UploadSave.jspx, let's test the first 3 parts now on my Tomcat 7 server by copying all 3 pages to \local\apache-tomcat-7.0.32\webapps\ROOT.
Then I run IE (Internet Explorer) 8.0 with http://localhost:8080/UploadInit.html. I got the form for changing file upload options:
File Upload Test Settings: File upload handler: [UploadDump.jspx] Submit method: [get ] Encryption type: [application/x-www-form-urlencoded] Submit
Without changing any values in the form, I clicked the submit button. I got the file upload form:
File Upload Form: Your email: [firstname.lastname@example.org ] Your comments: [I am uploading two files: ] [ hello.txt ] [ dot.gif ] File 1: [ ] Browse... File 2: [ ] Browse... Submit
To continue the test, I used the "Browse..." button, and selected two local files, C:\hello.txt and C:\dot.gif, into "File 1" and "File 2" input fields. Then clicked the Submit button, I got a blank page.
Why? Because the submit method was set to "get". As you remember, the "get" method requires the browser to submit all input fields in the HTTP request header. In fact, if you look at the address field of the browser, you would see the URL encoded input fields appended at the end of the URL:
http://localhost:8080/jsp/UploadDump.email@example.com& comment=+I+am+uploading+two+files%3A%0D%0A+++hello.txt%0D%0A+++dot.gi f&file1=C%3A%5Chello.txt&file2=D%3A%5Cdot.gif&submit=Submit
Last update: 2012.
Table of Contents