我正在创建一个简单的项目,允许我使用gwt上传和下载文件.我在下载服务器上的文件时遇到问题.
对于文件上传,我使用了http://code.google.com/p/gwtupload/并按照其中的说明操作.我的文件存储在网站容器外部的服务器上(在硬盘上),
现在,在下载文件时,我希望用户按下下载按钮,当前选择的任何项目都将下载.我真的不知道如何做到这一点
我知道我需要一个下载servlet
public class DownloadAttachmentServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String fileName = (String) req.getSession().getAttribute("fileName");
YFUser user = (YFUser) req.getSession().getAttribute(TestServiceImpl.SESSION_USER);
if (user == null)
throw new ServletException("Invalid Session");
InputStream in = null;
OutputStream out = resp.getOutputStream();
FileInputStream fIn = new FileInputStream(fileName);
byte[] buffer = new byte[4096];
int length; …Run Code Online (Sandbox Code Playgroud)