上述代码即可完成文件上传
  文件下载
  视图文件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方法.