日期:2014-05-18  浏览次数:20619 次

struts上传图片
请求帮助 我把图片上传到服务器端,怎么在获得这个图片啊
我获得图片在tomcat下的路径 为什么获得不到图片??

------解决方案--------------------
Struts2图片上传

html页面代码:
HTML code

<tr>
                                        <td align="right">业务图片:</td>
                                         <td><input type="file" name="file" id="imgurl" style="border:1px solid #7F9DB9;"/><span class="checkts">&nbsp;&nbsp;&nbsp;&nbsp;*</span><span class="sm">&nbsp;&nbsp;&nbsp;&nbsp;说明:游戏图片</span><br/></td>                                   
                                   </tr>

------解决方案--------------------
你可以在system.properties中定义你的路径名
TempFilePath = C:\\1\\
RealFilePath = C:\\2\\

String filepath = PropertyUtil.getProperty("TempFilePath");
String drcPath = filepath+compid+File.separatorChar;
File drcpath = new File(drcPath);
File file =new File(drcPath+ this.getUploadFileName());
if(!drcpath.exists()){
drcpath.mkdirs();

}
if(!file.exists()){
02Service.copy(this.upload, file);
// file.delete();
}

return SUCCESS;
public void copy(File src, File dst){

try {
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(src), Ass02Constant.BUFFER_SIZE);
out = new BufferedOutputStream( new FileOutputStream(dst), Ass02Constant.BUFFER_SIZE);
byte [] buffer = new byte [Ass02Constant.BUFFER_SIZE];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
} finally {
if ( null != in) {
in.close();
}
if ( null != out) {
out.close();
}
}


} catch (Exception e) {
e.printStackTrace();
}

}