JSP中输出CSV文件
<%@page import="com.opensymphony.xwork2.util.ValueStack"%><%
ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");
String aa = (String)vs.findValue("downloadContent");
response.setContentType("application/csv");
response.setHeader("Content-Disposition", "inline; filename=result.csv");
out.print(aa);
%>
相关文档:
第一步:建立一个code.jsp的页面,产生随机码
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"
import="java.io.*,
java.util.*,
& ......
//下面,从请求中得到属性 为一个 类,,会判断是否为null,,如为null则实例化
// id 值 相当于 class 的 对象名
<jsp:useBean id="order" class="com.entity.Order" scope="request" />
<==>
<%
Order order=(Order)request.getAttribute("order");
if(order==null)
  ......
将参数写成 java.net.URLEncoder.encode(sContent,"gb2312")后再传递。
比如url是"/accept.do?content=<%=java.net.URLEncoder.encode(sContent,"UTF-8")%>";
读取时,使用
String sc = new String(request.getParameter("content").getBytes("iso-8859-1"),"UTF-8"); ......
在action里使用fileupload时,从reqeust得到的中文数据为乱码,尝试使用了
Java代码
1. DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEnco ......