| Server IP : 23.94.149.180 / Your IP : 216.73.216.147 Web Server : nginx/1.20.1 System : Linux deadrock 5.14.0-741.22.1.el9_9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov 12 15:18:14 UTC 2026 x86_64 User : apache ( 48) PHP Version : 8.6.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /files/www/voxsupport/files/fancy/docs/userguide/HTML/ |
Upload File : |
<html>
<head>
<title>JSP example</title>
<meta name="generator" content="Help & Manual">
<meta name="keywords" content="">
</head>
<!-- Redirect browser to index page if page is not in the content frame.
This script is only valid for regular HTML export -->
<script language="JavaScript">
<!--
if(top.frames.length==0) top.location.href='index.html?jspexample.html'
//-->
</script>
<body bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#E2E2E2">
<tr>
<td align="left">
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><span style="font-family:Helvetica,Arial; font-size:12pt; color:#000080"><b>JSP example
<br>
</b></span></span>
</td>
<td align="right">
<font face="Arial" size="2">
<a href="javaScript:parent.reDisplay('1.1',1,0)"><img src="ico_nav_up.gif" border=0 alt="Top"></a>
<a href="javaScript:parent.reDisplay('3.3',1,0)"><img src="ico_nav_back.gif" border=0 alt="Previous"></a>
<a href="javaScript:parent.reDisplay('3.5',1,0)"><img src="ico_nav_next.gif" border=0 alt="Next"></a>
</font>
</td>
</tr>
</table>
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">The example below demonstrates how using a JSP script you can process files submitted by HTTP File Upload Applet. The source code for this example may be found in the <span style="font-family:Courier New; font-size:10pt; color:#000000">examples/jsp/receiver.jsp</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> file included with the HTTP File Upload Applet distribution. The file upload classes found in the Jakarta FileUpload package are required for this example to work. You may download the Jakarta FileUpload classes here:
<br>
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#0000FF"><u><span class="weblink"><a href="http://jakarta.apache.org/commons/fileupload/" target="_blank">http://jakarta.apache.org/commons/fileupload/</a></span></u></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#008000"><b>Example</b></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<br>
</span><span style="font-family:Courier New; font-size:10pt; color:#000000"><%@ page import=<span style="font-family:Courier New; font-size:10pt; color:#000080">"java.io.*"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> %>
<br>
<%@ page import=<span style="font-family:Courier New; font-size:10pt; color:#000080">"java.util.*"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> %>
<br>
<%@ page import=<span style="font-family:Courier New; font-size:10pt; color:#000080">"org.apache.commons.fileupload.*"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> %>
<br>
<%
<br>
String currentDirectory = <span style="font-family:Courier New; font-size:10pt; color:#000080">""</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">;
<br>
String file = <span style="font-family:Courier New; font-size:10pt; color:#000080">""</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">;
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// Define upload directory, notice that permissions to write are needed for upload directory </i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
String uploadDir = <span style="font-family:Courier New; font-size:10pt; color:#000080">"/var/uploads/"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">;
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// Create a new file upload handler</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
DiskFileUpload upload = <span style="font-family:Courier New; font-size:10pt; color:#0000FF">new</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> DiskFileUpload();
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">try</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> {
<br>
List items = upload.parseRequest(request);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">for</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (<span style="font-family:Courier New; font-size:10pt; color:#0000FF">int</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> i = <span style="font-family:Courier New; font-size:10pt; color:#000080">0</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">; i < items.size(); i++) {
<br>
FileItem item = (FileItem) items.get(i);
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// As we are interested not in regular form fields, we filter only files</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">if</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (!item.isFormField()) {
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// the name of file to save</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
String fileName = item.getName();
<br>
<br>
currentDirectory = <span style="font-family:Courier New; font-size:10pt; color:#000080">""</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">;
<br>
file = <span style="font-family:Courier New; font-size:10pt; color:#000080">""</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">;
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//gets a directory array</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
String[] data = fileName.split(<span style="font-family:Courier New; font-size:10pt; color:#000080">"\\\\"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">if</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (data.length != <span style="font-family:Courier New; font-size:10pt; color:#000080">1</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">) {
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//Starts File name index</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">int</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> index = fileName.lastIndexOf(<span style="font-family:Courier New; font-size:10pt; color:#000080">"\\"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// The file name</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
file = fileName.substring(index + <span style="font-family:Courier New; font-size:10pt; color:#000080">1</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">, fileName.length());
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// The directory name</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
currentDirectory = fileName.substring(<span style="font-family:Courier New; font-size:10pt; color:#000080">0</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">, index);
<br>
} <span style="font-family:Courier New; font-size:10pt; color:#0000FF">else</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> {
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// There is not a directory name</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
file = fileName;
<br>
}
<br>
<br>
String newDirectory = uploadDir + currentDirectory;
<br>
File directoryFile = <span style="font-family:Courier New; font-size:10pt; color:#0000FF">new</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> File(newDirectory);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//Creates the directory when it is necessary</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
<span style="font-family:Courier New; font-size:10pt; color:#0000FF">if</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (!directoryFile.isDirectory()) {
<br>
directoryFile.mkdirs();
<br>
}
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// concat the default directory, the specified directory and the file name </i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
String completeName = (currentDirectory.equals(<span style="font-family:Courier New; font-size:10pt; color:#000080">""</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">) ? uploadDir
<br>
+ file
<br>
: uploadDir + currentDirectory + <span style="font-family:Courier New; font-size:10pt; color:#000080">"\\"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> + file);
<br>
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// save file</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
File uploadedFile = <span style="font-family:Courier New; font-size:10pt; color:#0000FF">new</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> File(completeName);
<br>
item.write(uploadedFile);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//if succeeded, print out the "success" code to notify applet the file was uploaded</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
out.print(<span style="font-family:Courier New; font-size:10pt; color:#000080">"RESP.100"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//flush the stream to speed up applet notification</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
out.flush();
<br>
}
<br>
}
<br>
} <span style="font-family:Courier New; font-size:10pt; color:#0000FF">catch</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (FileUploadException e) {
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>//if failed for some reason, print out the "failed" code to notify applet the file wasn't uploaded </i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
out.print(<span style="font-family:Courier New; font-size:10pt; color:#000080">"RESP.200"</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">);
<br>
<span style="font-family:Courier New; font-size:10pt; color:#008000"><i>// flush the stream to speed up applet notification</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
out.flush();
<br>
} <span style="font-family:Courier New; font-size:10pt; color:#0000FF">catch</span></span><span style="font-family:Courier New; font-size:10pt; color:#000000"> (Exception e) {
<br>
e.printStackTrace();
<br>
}
<br>
%>
<br>
<br>
</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Installation</b>
<br>
<br>
</span></span><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">1.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Change <span style="font-family:Courier New; font-size:10pt; color:#000000">uploadDir</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> variable to directory path where files should be uploaded. Make sure to include a </span><span style="font-family:Courier New; font-size:10pt; color:#000000">/</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> at the end and that the permissions to write are set properly.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">2.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Place required <span style="font-family:Courier New; font-size:10pt; color:#000000">commons-fileupload-1.0.jar</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> in </span><span style="font-family:Courier New; font-size:10pt; color:#000000">WEB-INF/lib</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> directory of application server. This jar file is part of the Jakarta FileUpload package.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">3.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Upload <span style="font-family:Courier New; font-size:10pt; color:#000000">receiver.jsp</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"> file to appropriate directory on application server.
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">4.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Set url parameter in HTML applet code to point to url of this script e.g. <span style="font-family:Courier New; font-size:10pt; color:#000000">http://www.jscape.com/appname/receiver.jsp</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span></span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="28"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">5.</span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Done. You may now run HTTP File Upload Applet
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
<span style="font-family:Courier New; font-size:10pt; color:#000000"></span></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>See also</b>
<br>
<br>
</span></span><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><a href=javaScript:parent.reDisplay('2.8',1,0)>Specifying the upload URL</a>
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span>
</body>
</html>