JSP Tutorials - Herong's Tutorial Examples - Version 4.03, by Dr. Herong Yang
Code 2 - Display Form - UploadForm.jspx
This section provides a tutorial example of a JSP page, UploadForm.jspx, presenting the file upload form page based the options selected by the user previously.
As Part 2 of the file upload test, here is my UploadForm.jspx page, that presents the file upload form page based the options selected by the user on the UploadInit.html page:
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
<!-- UploadForm.jspx
- Copyright (c) 2012, HerongYang.com, All Rights Reserved.
-->
<jsp:directive.page contentType="text/html"/>
<jsp:declaration><![CDATA[
private String getItem(String queryString, String key) {
String value = null;
if (queryString!=null) {
int i = queryString.indexOf(key);
if (i>-1) {
i = i + key.length();
int j = queryString.indexOf("&",i);
if (j>-1) {
value = queryString.substring(i,j);
} else {
value = queryString.substring(i);
}
if (value.startsWith("=")) {
value = value.replaceFirst("=","");
}
}
}
return value;
}
]]></jsp:scriptlet>
<jsp:scriptlet><![CDATA[
String queryString = request.getQueryString();
String action = getItem(queryString,"action");
String method = getItem(queryString,"method");
String enctype = getItem(queryString,"enctype");
if (enctype.equals("x-www-form-urlencoded"))
enctype = "application/x-www-form-urlencoded";
if (enctype.equals("form-data"))
enctype = "multipart/form-data";
out.println("<html><body>");
out.println("<b>File Upload Form</b>:<br/>");
out.println("<form action="+action+" method="+method
+" enctype="+enctype+">");
out.println("Your email:");
out.println("<input type=text name=email size=20><br/>");
out.println("Your comments:");
out.println("<textarea name=comment cols=20 rows=3></textarea>"
+"<br/>");
out.println("File 1:");
out.println("<input type=file name=file1 size=20><br/>");
out.println("File 2:");
out.println("<input type=file name=file2 size=20><br/>");
out.println("<input type=submit name=submit value=Submit><br/>");
out.println("</form>");
out.println("</body></html>");
]]></jsp:scriptlet>
</jsp:root>
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