怎样用java实现图片下载(输入输出流实现的下载)以后转跳到另一个页面?
public String download() throws IOException{HttpServletResponse response=Struts2Utils.getResponse();
BufferedOutputStream out = null;
String path = getHttpRequest().getContextPath();
String basePath = getHttpRequest().getScheme() + "://" + getHttpRequest().getServerName() + ":" + getHttpRequest().getServerPort()
+ path;
String picture=getHttpRequest().getParameter("picture");
String imageUrl=basePath+"/picture/"+picture+".jpg";
String filename = picture+".jpg";
filename = new String (filename.getBytes("utf-8"),"iso8859-1");
response.setContentType("APPLICATION/DOWNLOAD");
response.setHeader("Content-Disposition","attachment; filename="+ filename);
out = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8 * 1024];
URL u;
URLConnection connection = null;
try {
u = new URL(imageUrl);
connection = u.openConnection();
}catch (Exception e) {
System.out.println("ERR:" + imageUrl);
}
connection.setReadTimeout(100000);
InputStream is = null;
try {
is = connection.getInputStream();
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int len = 0;
while ((len = is.read(buffer)) != -1) {
bytestream.write(buffer, 0, len);
}
out.flush();
}catch (Exception e) {
e.printStackTrace();
}finally {
if (is != null) {
try {
is.close();
}catch (IOException e) {
}
}
if(out!=null){
out.close();
}
}
return "draw";
}
代码如上,我想通过图片下载以后让页面跳到抽奖页面,但是通过输入输出流实现图片下载后,程序执行到return但是不转跳。。同事说out.flush已经到前台了,所以后面return没用,写过一个test方法单独测试return "draw",可以转跳,求助高手,如何实现啊 Java 流 action
补充:Java , Web 开发