struts上传照片问题 急!急!急!

publicStringexecute(){System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");Str... public String execute()
{
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
String picname="";
String path=ServletActionContext.getServletContext().getRealPath("impimage");
if(!ManageDB.hasImp(this.impId))
{
if(this.getPicFileName()!=null&&(!this.getPicFileName().equals("")))
{
picname=this.getImpId()+this.getPicFileName().subSequence(this.getPicFileName().lastIndexOf("."),this.getPicFileName().length());
try
{System.out.println(path+"\\"+picname);
File file=new File(path+"\\"+picname);
FileOutputStream fos=new FileOutputStream(file);
BufferedOutputStream bos=new BufferedOutputStream(fos);
FileInputStream fis=new FileInputStream(getPic());
BufferedInputStream bis=new BufferedInputStream(fis);
byte[] buffer=new byte[16*1024];
//int length=0;
System.out.println(fis.read(buffer));
while(bis.read(buffer)>0)
{
System.out.println("kong");
bos.write(buffer,0,buffer.length);
}
}
catch(Exception e)
{
// this.setResult("提交失败");
// return SUCCESS;
}
}
if(ManageDB.addImp(this.getImpId(),this.getImpName(),this.getImpGender(),this.getImpBirth(),
this.getImpEmail(),this.getDepartId(),this.getImpRoll(),this.getImpSalary(),this.getImpTel(),
picname,this.getImpBio(),path.substring(1,path.length())+"/"))
{
this.setResult("提交成功");
}
else
{System.out.println("sdfsfsdf");
this.setResult("提交失败");
}

}
else
{
this.setResult("已经有该编号的员工!请重新输入!");
}

return SUCCESS;
}
我的代码是这么写的,但是根本运行不到while,在tomcat里面有那个图片的名字了,但是没有图片预览,跪求大神解决啊!!!需要什么文件,页面代码请告诉我。急!!
展开
 我来答
fylsh
2012-05-31 · TA获得超过950个赞
知道小有建树答主
回答量:1472
采纳率:0%
帮助的人:1078万
展开全部
应该是你文件读操作有点问题:
byte[] buffer=new byte[16*1024];
int len=-1;
while((len=bis.read(buffer))!=-1)
{
bos.write(buffer,0,len);
}
bos.flush();
bos.close();
bis.close();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式