首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSP页面导出word文档求解解决思路

2013-12-07 
JSP页面导出word文档求解JSP页面是这样的 数据已经取出来了 传form对象到后台form namef1 actionout

JSP页面导出word文档求解
JSP页面是这样的 数据已经取出来了 传form对象到后台
<form name="f1" action="out" method="post">
    <table border="1">
    <tr><td height='30' colspan="2"></td></tr>
    <tr>
    <td width="50%">资产数量</td>
    <td>资产总金额</td>
    </tr>
    <tr>
    <td><input type="text" id="num" disabled="disabled"/></td>
    <td><input type="text" id="sum" disabled="disabled"/></td>
    </tr>
    <tr>
    <td colspan="2">资产明细列表</td>
    </tr>
    <tr>    
 <table id="t1">
 
 <tr>
 <th><input type="checkbox" name="chkAll" id="chkAll" onclick="ChkAllClick('chkSon','chkAll')"/></th>
 <th>资产细目</th>
 <th>资产名称</th>
 <th>资产编号</th>
 <th>资产单价</th>
 <th>原使用人</th>
 <th>数量11</th>
 </tr>
 
 <s:iterator value="list">
 <tr>
 
 <th><input type="checkbox" id="chkSon" name="chkSon" onClick="GetRow()"/></th>
 <th align="center" ><input type="text" disabled="disabled" value="${XIMU }"/></th>
 <th><input type="text" disabled="disabled" value="${MINGCHEN }"/></th>
 <th><input type="text" disabled="disabled" value="${BIANHAO }"/></th>
 <th><input type="text" disabled="disabled" value="${DANJIA }"> </th>
 <th><input type="text" disabled="disabled" value="${SHIYONGREN}"/></th>
 <th><input type="text" disabled="disabled" value="${SHULIANG}"> </th>
 </tr>
 </s:iterator>
 </table>   
    
    </tr>
    <tr><td colspan="2">
    <input type="button" value="统计" onclick="tj()" class="btn" />
    <input type="button" value="删除" onclick="del()" class="btn" />
    <input type="submit" value="导出" class="btn" />
       </td>     
    </tr>
    </table>
    </form>

后台是这样的
public void out(){
if(f1!=null){
        String fileName="";
        fileName+="评价报告.doc";
   try {
              HttpServletResponse response = ServletActionContext.getResponse();
              response.setHeader("Content-disposition","attachment; filename="+new String(fileName.getBytes("GB2312"), "8859_1"));
        } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
        }
       }else{
       System.out.println(f1);
       }
}
f1已经get()了
打印出来的f1是空 我觉得我是不是传的时候就写错了···
[解决办法]
你f1是什么啊,那是form的名字啊!你获取这个肯定是null
[解决办法]
应该取表单里的元素的值啊,
[解决办法]
页面上的数据是从数据库里查出来的吗。如果是,导出的时候直接从数据库里取数据就行了

热点排行