专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Web开发

struts上传图片,该怎么处理

发布时间:2010-05-31 07:02:56 文章来源:www.iduyao.cn 采编人员:星星草
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();
}

}

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: