
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里面有那个图片的名字了,但是没有图片预览,跪求大神解决啊!!!需要什么文件,页面代码请告诉我。急!! 展开
{
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里面有那个图片的名字了,但是没有图片预览,跪求大神解决啊!!!需要什么文件,页面代码请告诉我。急!! 展开
1个回答
展开全部
应该是你文件读操作有点问题:
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();
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();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询