struts2如何上传图片并在同一jsp中显示出来
展开全部
//action的关键代码
import com.xt.gyz.facelook.service.FacesService;
public class ShowPic extends ActionSupport {
private InputStream is;
private Integer id;
private FacesService facesService;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setFacesService(FacesService facesService) {
this.facesService = facesService;
}
public InputStream getIs() {
return is;
}
public void setIs(InputStream is) {
this.is = is;
}
@Override
public String execute() throws Exception {
Faces face=facesService.findById(id);
is=new ByteArrayInputStream(face.getPic());
// FileOutputStream fos=new FileOutputStream(new File("E:/body.jpg"));
// System.out.println(fos);
// System.out.println("face:"+face.getPic().length);
// fos.write(face.getPic());
// fos.flush();
// fos.close();
return super.execute();
}
}
//不要忘记struts.xml配置
......
<action name="showPic" class="showPicAction">
<result type="stream">
<param name="inputName">is</param>
<param name="contectType">image/jpg</param>
</result>
</action>
.....
这样就可以啦
import com.xt.gyz.facelook.service.FacesService;
public class ShowPic extends ActionSupport {
private InputStream is;
private Integer id;
private FacesService facesService;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setFacesService(FacesService facesService) {
this.facesService = facesService;
}
public InputStream getIs() {
return is;
}
public void setIs(InputStream is) {
this.is = is;
}
@Override
public String execute() throws Exception {
Faces face=facesService.findById(id);
is=new ByteArrayInputStream(face.getPic());
// FileOutputStream fos=new FileOutputStream(new File("E:/body.jpg"));
// System.out.println(fos);
// System.out.println("face:"+face.getPic().length);
// fos.write(face.getPic());
// fos.flush();
// fos.close();
return super.execute();
}
}
//不要忘记struts.xml配置
......
<action name="showPic" class="showPicAction">
<result type="stream">
<param name="inputName">is</param>
<param name="contectType">image/jpg</param>
</result>
</action>
.....
这样就可以啦
2014-05-24
展开全部
可以用Jquery上传图片插件,可以到网上搜下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询