struts2 fileupload乱码的问题
jsp页面编码为utf-8,上传代码如下:
<s:form action="upload" theme="simple" enctype="multipart/form-data" method="post">
<table align="center" width="50%" border="1">
<tr>
<td>username</td>
<td>
<s:textfield name="username"></s:textfield>
</td>
</tr>
<tr>
<td>password</td>
<td>
<s:password name="password"></s:password>
</td>
</tr>
<tr>
<td>file</td>
<td id="more">
<s:file name="file"></s:file><input type="button" value="Add More..." onclick="addMore()">
</td>
</tr>
<tr>
<td>
<s:submit value="submit"></s:submit>
</td>
<td>
<s:reset value="reset"></s:reset>
</td>
</tr>
</table>
</s:form>
struts.xml配置文件如下:
<action name="upload" class="com.test.action.UploadAction">
<result name="success">/uploadResult.jsp</result>
<result name="input">/upload.jsp</result>
</action>
action文件execute代码如下:
for(int i=0; i < file.size() ; i++){
InputStream is = new FileInputStream(file.get(i));
String root = ServletActionContext.getRequest().getRealPath("/upload");
System.out.println(root);
File destFile = new File(root,this.getFileFileName().get(i));
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[400];
int length = 0;
while((length = is.read()) > 0){
os.write(buffer,0,length);
}
is.close();
os.close();
}
return SUCCESS;
}
上传后的文件为乱码,请高手指点一下?