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="" version="2.1">
<!-- UploadForm.jspx
 - Copyright (c) 2012,, All Rights Reserved.
< contentType="text/html"/>
   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;
   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("<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>"
   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/>");

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

File Upload Test Application

 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 1 - GET Method - Failed

 Test 2 - POST Method - Successful

 Code 4 - Save File - UploadSave.jspx

 Test 3 - Save File - Successful

 Code Review - UploadSave.jspx

 Outdated Tutorials


 PDF Printing Version