jsp超级链接实现"目标另存为"功能

ZDNet软件频道 时间:2008-07-01 作者: | 中国IT实验室 我要评论()
本文关键词:实现 链接 JSP
jsp超级链接实现"目标另存为"功能

JSP:


<%...@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<a href="/test/test.do">1322</a>
</body>
</html>
 action:


package action;

import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class TeAction extends Action ...{

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception ...{
        // TODO Auto-generated method stub
   
         StringBuilder sb = new StringBuilder();
         sb.append("1");
         response.addHeader("Content-Disposition", "attachment; filename=test.txt");
         response.setContentType("application/octet-stream");
         response.setCharacterEncoding("GB2312");
         response.getWriter().write(sb.toString());
         response.flushBuffer();


        return null;
    }
}


百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134