uploadfile.jsp
来自「精通tomcat书籍原代码,希望大家共同学习」· JSP 代码 · 共 182 行
JSP
182 行
<%
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
%>
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/dlog4j.tld" prefix="dlog" %>
<!-- based on insimage.dlg -->
<jsp:useBean id="filePath" class="java.lang.String" scope="request"/>
<jsp:useBean id="fileName" class="java.lang.String" scope="request"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML 3.2//EN">
<HTML id=dlgImage>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<meta http-equiv="MSThemeCompatible" content="Yes">
<TITLE><bean:message key="UPLOAD_FILE_TITLE" bundle="html"/></TITLE>
<style>
html, body, button, div, input, select, td, fieldset { font-family: "Verdana", "Arial"; font-size: 12px; };
</style>
<SCRIPT>
// if we pass the "window" object as a argument and then set opener to
// equal that we can refer to dialogWindows and popupWindows the same way
opener = window.dialogArguments;
var _editor_url = opener._editor_url;
var objname = 'content';
var config = opener.document.all[objname].config;
var editor_obj = opener.document.all["_" +objname+ "_editor"];
var editdoc = editor_obj.contentWindow.document;
function _CloseOnEsc() {
if (event.keyCode == 27) { window.close(); return; }
}
window.onerror = HandleError
function HandleError(message, url, line) {
var str = "An error has occurred in this dialog." + "\n\n"
+ "Error: " + line + "\n" + message;
alert(str);
// window.close();
return true;
}
function Init() {
document.body.onkeypress = _CloseOnEsc;
<logic:notEmpty name="filePath">
uploadFileForm.fileUrl.value='<bean:write name="filePath"/>';
uploadFileForm.imgType[1].checked=true;
btnOKClick();
</logic:notEmpty>
}
function _isValidNumber(txtBox) {
var val = parseInt(txtBox);
if (isNaN(val) || val < 0 || val > 9999) { return false; }
return true;
}
function _isValidNumber(txtBox) {
var val = parseInt(txtBox);
if (isNaN(val) || val < 0 || val > 999) { return false; }
return true;
}
function btnOKClick() {
var curRange = editdoc.selection.createRange();
// error checking
with(uploadFileForm){
itype = "file";
for (var i=0; i<imgType.length; i++){
if(imgType[i].checked)
itype = imgType[i].value;
}
if (itype=="url" && (!fileUrl.value || fileUrl.value=="" || fileUrl.value == "http://")) {
alert("<bean:message key="UPLOAD_FILE_URL_TIP" bundle="html"/>");
fileUrl.focus();
return false;
}
if (itype=="file" && uploadFile.value=="") {
alert("<bean:message key="UPLOAD_FILE_PATH_TIP" bundle="html"/>");
uploadFile.focus();
return false;
}
if(itype=="file"){
btnOK.disabled=true;
uploadFileForm.submit();
return;
}
// delete selected content (if applicable)
/*
if (editdoc.selection.type == "Control" || curRange.htmlText) {
if (!confirm("Overwrite selected content?")) { return; }
curRange.execCommand('Delete');
curRange = editdoc.selection.createRange();
}
*/
var fileName=fileUrl.value;
<logic:notEmpty name="fileName">
fileName='<bean:write name="fileName"/>';
</logic:notEmpty>
var file = '<a href="'+fileUrl.value+'" target=_blank>'+fileName+'</a>\n';
opener.editor_insertHTML('content', file);
}
// insert table
window.close();
}
</SCRIPT>
</HEAD>
<BODY id=bdy onload="Init()" style="background: threedface; color: windowtext;" scroll=no>
<html:form name="uploadFileForm" action="/uploadFile" type="dlog4j.formbean.UploadFileForm" enctype="multipart/form-data">
<font color="red"><html:errors/></font>
<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<fieldset>
<legend><bean:message key="UPLOAD_FILE_SOURCE" bundle="html"/>: </legend>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td colspan=2>
<html:hidden styleId="allowExt" name="uploadFileForm" property="allowExt" value="TXT|RAR|ZIP|EXE|DOC|XLS|CHM|HLP"/>
<html:hidden styleId="maxSize" name="uploadFileForm" property="maxSize" value="1000000"/>
<bean:message key="UPLOAD_FILE_SOURCE" bundle="html"/>:
<input type="radio" name="imgType" value="file" onclick="picfile.style.display='';picurl.style.display='none'" checked><bean:message key="UPLOAD_FILE_LOCAL" bundle="html"/>
<input type="radio" name="imgType" value="url" onclick="picurl.style.display='';picfile.style.display='none'"><bean:message key="UPLOAD_FILE_NET" bundle="html"/>
</td>
</tr>
<tr id=picurl style="display:none">
<td colspan=2>
<bean:message key="UPLOAD_FILE_URL" bundle="html"/>:
<html:text styleId="fileUrl" size="50" name="uploadFileForm" property="fileUrl" value="http://" tabindex="10" onfocus="select()"/>
</td>
</tr>
<tr id=picfile >
<td colspan=2>
<bean:message key="UPLOAD_FILE_FILE" bundle="html"/>:
<html:file styleId="uploadFile" size="40" name="uploadFileForm" property="uploadFile" tabindex="10" onfocus="select()"/>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr><td height=5></td></tr>
<tr><td align=right><input ID=btnOK type=button tabIndex=40 onclick="btnOKClick();" value="<bean:message key="OK" bundle="html"/>"> <input ID=btnCancel type=reset tabIndex=45 onClick="window.close();" value="<bean:message key="CANCEL" bundle="html"/>"></td></tr>
</table>
</html:form>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?