xycshh 2009-09-09 08:47
浏览 228
已采纳

为什么我上传的图片搜索出来那么小

public void copy(File image ,File dst){
InputStream in=null;
OutputStream out=null;
try{
in=new BufferedInputStream(new FileInputStream(image),BUFFER_SIZE);
out=new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
int len=0;
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(in!=null)try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
if(out!=null)try{
out.close();
}catch(IOException e){
e.printStackTrace();
}
}

}
@SuppressWarnings("unchecked")
public String execute()throws Exception{
[size=large]String dstpath=ServletActionContext.getServletContext().getRealPath(this.getSavepath()+"//"+this.getImageFileName());//建立文件路径[/size]
File dst=new File(dstpath);
copy(this.image,dst);
Product p=new Product();
p.setFkind(this.getFkind());
p.setIntro(this.getIntro());
p.setName(this.getName());
p.setNumber(this.getNumber());
p.setPrice(this.getPrice());
p.setSkind(this.getSkind());
p.setUploadTime(new Date(System.currentTimeMillis()));
[size=large]p.setImagepath(dstpath);//保存路径[/size] User u=(User)(ActionContext.getContext().getSession().get("user"));
p.setUserid(u.getId());
ActionContext.getContext().getSession().put("product", p);
productserivce.saveProduct(p);
return "success";

}
"/>
显示出来的图片很小(好像是没有)是不是路径出错了

[b]问题补充:[/b]
public void copy(File image ,File dst){
InputStream in=null;
OutputStream out=null;
try{
in=new BufferedInputStream(new FileInputStream(image),BUFFER_SIZE);
out=new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
int len=0;
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(in!=null)try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
if(out!=null)try{
out.close();
}catch(IOException e){
e.printStackTrace();
}
}

}
@SuppressWarnings("unchecked")
public String execute()throws Exception{
[size=large]String dstpath=ServletActionContext.getServletContext().getRealPath(this.getSavepath()+"//"+this.getImageFileName());//建立文件路径[/size]
File dst=new File(dstpath);
copy(this.image,dst);
Product p=new Product();
p.setFkind(this.getFkind());
p.setIntro(this.getIntro());
p.setName(this.getName());
p.setNumber(this.getNumber());
p.setPrice(this.getPrice());
p.setSkind(this.getSkind());
p.setUploadTime(new Date(System.currentTimeMillis()));
[size=large]p.setImagepath(dstpath);//保存路径[/size] User u=(User)(ActionContext.getContext().getSession().get("user"));
p.setUserid(u.getId());
ActionContext.getContext().getSession().put("product", p);
productserivce.saveProduct(p);
return "success";

}
"/>
显示出来的图片很小(好像是没有)是不是路径出错了
我是把路径保存在数据库当中,然后取出来。
[b]问题补充:[/b]
好像是没有图片吧!我点击右键想复制它 却没有显示“复制”
[b]问题补充:[/b]
我在显示图片的action里面加了System.out.print(p.getImagepath());
结果路径是:E:\workspace.metadata.plugins\com.genuitec.eclipse.easie.tomcat.myeclipse\tomcat\webapps\shopping\upload\p.gif
也没有出错啊!
是上面"/>
这句出错了吗?
[b]问题补充:[/b]
是这样的,挺大
[b]问题补充:[/b]
上面的action执行后 还回一个页面,页面有段显示图片的代码图片:"/>这样显示是正常的,然后后面却不行了
[b]问题补充:[/b]
谢谢了,第一位朋友说得也没错,不过那段代码不知道怎么写。可是我里面怎么没分了。真不好意思。奇怪的是没分怎么也可以提问啊!谢谢各位了。

  • 写回答

3条回答 默认 最新

  • iteye_10013 2009-09-09 09:09
    关注

    " width=1000 height=1000/>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多