yunye 的 JavaBlog

@see codemouse

统计

留言簿(1)

阅读排行榜

评论排行榜

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

jsp:


<% @ page language = " java "  contentType = " text/html; charset=GB18030 "
    pageEncoding
= " GB18030 "
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< 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 ;
    }

}

posted on 2008-03-22 01:40 yunye 阅读(795) 评论(1)  编辑  收藏 所属分类: jsp

评论

# re: jsp超级链接实现"目标另存为"功能 [未登录] 2012-05-15 10:26 李四

目标另存为  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: