???????????????????????
???????????
??????????filedownload.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>???????</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1??keyword2??keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h2>????????????</h2><br/>
Dream.jpg:<a href="FileDownload.action">???????</a><br/>
</body>
</html>
????action?? ????????????
package com.oumyye.action;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
//???????
public class FileDownload extends ActionSupport{
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
//???????????????????????????????????????????????????????????? ?????
public InputStream getDownloadFile() throws Exception
{
this.fileName = "hello.jpg" ;
//??????·??
return ServletActionContext.getServletContext().getResourceAsStream("upload/"+this.fileName) ;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
}
??????????????
????????????????????
????Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
????????????1.???·??????????????????????????????£?????????InputStream????????????system.out.println()???????£????null??????·??????????????????Щ???????????????
????2.??action?????д?????????"<param name="inputName">"????????????get????.