forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupimg_upload.jsp
More file actions
143 lines (121 loc) · 3.62 KB
/
upimg_upload.jsp
File metadata and controls
143 lines (121 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="electric.electricUtils.ParamUtils"%>
<%@ page import="com.jspsmart.upload.*"%>
<%
String uploadedPathName="";//
String uploadedFileName="";
double uploadedFileSize=0;
boolean bSuccessed=false;
boolean bControl=true;
com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing()&&i==0) {
java.util.Random rnd=new java.util.Random(new java.util.Date().getTime()+1);
long lRand=rnd.nextLong();
long tRand=new java.util.Date().getTime();
String strRand=new Long(lRand).toString()+new Long(tRand).toString();
uploadedPathName="/uploads/kxi_"+strRand+"."+myFile.getFileExt();
uploadedFileName="kxi_"+strRand+"."+myFile.getFileExt();
uploadedPathName=uploadedPathName.replace('-','_');
uploadedFileName=uploadedFileName.replace('-','_');
myFile.saveAs(uploadedPathName);
uploadedFileSize=myFile.getSize()/1024;
bSuccessed=true;
break;
}
}
String formName=mySmartUpload.getRequest().getParameter("formname");
String controlName=mySmartUpload.getRequest().getParameter("controlname");
String imageHandle=mySmartUpload.getRequest().getParameter("imagename");
if(formName==null)
{
formName="";
}
if(controlName==null)
{
controlName="";
}
if(imageHandle==null)
{
imageHandle="";
}
if(formName.trim().equals("")||controlName.trim().equals("")||imageHandle.trim().equals(""))
{
bControl=false;
}
%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>图片上传完成</title>
<style>
<!--
td,th,tr,table,body{font-size:9pt}
-->
</style>
<script language="javascript">
<!--
function ImgOk()
{
opener.document.<%=formName%>.<%=controlName%>.value='<%=uploadedPathName%>';
opener.document.<%=formName%>.<%=imageHandle%>.src='<%=uploadedPathName%>';
window.close();
}
//-->
</script>
</head>
<body>
<%
//com.ayaya.AccessLog log=new com.ayaya.AccessLog(request,session);
if(bSuccessed)
{
%>
<table border="1" cellpadding="3" cellspacing="0" width="400">
<tr>
<td width="390" colspan="4" height="24">
<p align="center">图片上传成功</td>
</tr>
<tr>
<td width="91" height="18">上传后文件名:</td>
<td width="74" height="18"><%=uploadedFileName%> </td>
<td width="110" height="18">文件大小(KB):</td>
<td width="91" height="18"><%=uploadedFileSize%></td>
</tr>
<tr>
<td width="390" height="92" colspan="4"><img border="0" src="<%=uploadedPathName.substring(1,uploadedPathName.length())%>" width="383" height="256"></td>
</tr>
<tr>
<%
if(bControl)
{
%>
<td width="390" height="19" colspan="4"><input type="button" name="btn" value="确定并返回" onclick="JavaScript:ImgOk();"></td>
<%
}
else
{
%>
<td width="390" height="19" colspan="4"><input type="button" name="btn" value="确定并返回" onclick="JavaScript:window.close();"></td>
<%
}
%>
</tr>
</table>
<%
}
else
{
%>
图像上传失败!<BR><BR><BR><BR>
<input type="button" name="btn" value="关闭窗口" onclick="JavaScript:window.close();">>
<%
}
%>
</body>
</html>