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: [herong_yang@yahoo.com ] Your comments: [I am uploading two files: ] [ hello.txt ] [ dot.gif ] File 1: [ ] Browse... File 2: [ ] Browse... Submit
Observe that:
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.jsp?email=herong_yang@yahoo.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
JSP (JavaServer Pages) Overview
Tomcat 7 Installation on Windows Systems
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Overview of JSTL (JSP Standard Tag Libraries)
Multiple Tags Working Together
RFC 1867 - Form-based File Upload in HTML
Code 1 - Display Options - UploadInit.html
Code 2 - Display Form - UploadForm.jspx
Code 3 - Dump File - UploadDump.jspx
Test 2 - POST Method - Successful
Code 4 - Save File - UploadSave.jspx