调用的地方
<a onClick="javascript:window.open(\'jsp/uploadphoto.jsp\',\'myfacewindow\', \'height=100,width=440, top=350, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no\');" style="cursor:hand;"><span class="STYLE2">上传</span></a> 推荐最佳比例为:(50px*50px)
下面是上传的界面 uploadphoto.jsp
<%@page contentType="text/html; charset=GBK" import="java.util.HashMap"%>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {
font-size: 12px;
color: #000000;
}
.STYLE2 {
color: #006699;
font-weight: bold;
}
-->
</style>
<html>
<title>上传图片</title>
<body> <br/>
<span class="STYLE2">商务客图片上传</span><br/>
<span class="STYLE1">请您选择您要上传的图片,图片推荐:50像素*50像素!使用.jpg .gif .bmp格式</span>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form id="uploadphoto_f" name="uploadphoto_f" enctype="multipart/form-data" method="post" action="../uploadphoto.do">
<tr>
<td height="41">
<input name="flag" type="hidden" value="myface" />
<input name="loadpathto" type="hidden" value="/uploadcard/myface/" />
<input name="uploadphoto" type="file" id="uploadphoto" size="40" />
<input name="upload_b" type="submit" id="upload_b" value=" 上传 " /></td>
</tr></form>
</table>
</body>
</html>
<%String msg=request.getAttribute("msg")==null?"":request.getAttribute("msg")+"";
if(!msg.equals("")){
%>
<script>
opener.document.location.href="Userinfo.do";
window.close();
</script>
<%}%>
接着是FORM 类 uploadphotoForm
package com.onlysoft.txl.user;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: fishsoft</p>
*
* @author Danny
* @version 1.0
*/
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;
public class uploadphotoForm extends ActionForm {
protected FormFile uploadphoto;
public FormFile getUploadphoto() {
return uploadphoto;
}
public void setUploadphoto(FormFile theFile) {
this.uploadphoto = theFile;
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = null;
//has the maximum length been exceeded?
Boolean maxLengthExceeded =
(Boolean) request.getAttribute(
MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
if ( (maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
errors = new ActionErrors();
errors.add(
ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("maxLengthExceeded"));
}
return errors;
}
}
这个是action类 uploadphotoAction
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