tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shanx" <>
Subject Re: Multipart form handling help
Date Thu, 23 Nov 2000 14:20:58 GMT

Thanks to all that answered. I have figured out a simple but creative
approach which might be a BIT patchy, but it works like a charm for me. I
dont need to bother with MULTIPART stuff at all!

In essence, what I do is that when the form is submitted, I use simple
Javascript to change the path of the selected image to a URL such as :

I pass this value to the jsp file, and put it in the IMG SRC of the next
page. Cool huh? Works just fine for my purposes, and is so much faster you
wont believe it - because there is no rigmarole of handling it with
MultipartRequest.Java stuff and no dealing with byte arrays and all that..!

I am including the code for the benefit of posterity. :)

Comments/caveats welcome,

PS: There are two files: UPLOAD.HTM and the file to which the form is
submitted, UPLOAD.JSP..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<title>File upload test</title>
function doConvertImagePath(imagePathField, relatedPathField)
    var theValue = document.theform.file.value;
    theValue = "file://" + theValue.replace('\\', '/');
     document.theform.file_path.value = theValue;

function doPreviewImage1()
    var theValue = document.theform.file.value;
    if (theValue != "")
        theValue = "file://" + theValue.replace('\\', '/');
        theValue = "blank.gif";
    document.previewImage.src = theValue;

function compute()
    // Change all the related file paths
    return true;

<style type="text/css">
td {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt}
input {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt}


<form name="theform" action="upload.jsp" onSubmit="return compute();"
  <table width="100%" border="0" cellspacing="0" cellpadding="3">
      <td width="100"><b>Select file:</b></td>
      <td width="200">
        <input type="file" name="file" onChange="doPreviewImage1()"
        <input type="hidden" name="file_path">
      <td rowspan="2"><img name="previewImage" src="blank.gif" width="100"
height="100" style="display: none"></td>
      <td><b>Select desc:</b></td>
        <input type="text" name="desc">
      <td> <br>
        <input type="submit" value="Preview.." name="submit">




Now, in the JSP file, I just IMAGE SRC is to the passed value, as follows:

<%@ page language="java" session="true" %>

<font face=verdana size=1>
<b>The image</b>: <br>
<img src="<% out.print(request.getParameter("file_path")); %>">
<b>The description</b>: <br>
<% out.print(request.getParameter("desc")); %>


View raw message