jsp构造出work文档之后,怎样通过一个Action把work文档保存,并且我不显示work文档
你既然都可以通过“jsp生成的word文档”那么你读取word里面的数据应该没什么难度了啊,你保存是下载到本地吗?你想要操作word的话给你推荐个jacob(开源的第三方工具包),你要是需要下载的话,我下面给你贴出来一个通过serlvet下载文件的类,配置在tomcat的web.xml后直接调用可以下载:
[color=orange]
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import utils.ReadSavePathImpl;
import inter.util.IReaderPath;
/**
public class FileDowndoadServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
@SuppressWarnings("deprecation")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("application/x-msdownload;charset=gb2312");
//取得文件名
String fileName = req.getParameter("fileName").trim();
if(null==fileName){
resp.sendRedirect(req.getContextPath()+"/error/error.jsp");
return;
}
//p("希望下载的文件名:"+fileName);
fileName = new String(fileName.getBytes("iso-8859-1"),"gb2312");
//p("希望下载的文件名:"+fileName);
//取得文件保存的路径
IReaderPath readerPath = new ReadSavePathImpl();
@SuppressWarnings("all")
String filePath = req.getRealPath(readerPath.getDirectoryName());
resp.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gb2312"),"iso-8859-1"));
InputStream is = null;
OutputStream os = null;
try{
File file = new File(filePath,fileName);
if(!file.exists()){
resp.sendRedirect(req.getContextPath()+"/error/error.jsp");
return;
}
FileInputStream fis = new FileInputStream(file);
is= new BufferedInputStream(fis);
os = resp.getOutputStream();
byte[] buf = new byte[1024];
int len = 0;
while((len=is.read(buf,0,buf.length))>0){
os.write(buf,0,len);
}
}catch(Exception e){
p("文档下载异常:"+e.getMessage());
e.printStackTrace();
}finally{
try {
if (null != os) {
os.close();
}
} catch (Exception e) {
p("关闭输出流错误:" + e.getMessage());
}
try {
if (null != is) {
is.close();
}
} catch (Exception e) {
p("关闭输入流错误:" + e.getMessage());
}
}
}
private void p(Object obj){
System.out.println("[ FileDowndoadAction ]"+obj);
}
}
[/color]
java可以使用文件操作,只要能拿到内容,另存为一个文件就行了
可以参考 java io
你最好再详细说明一下你的需求,感觉不明白你具体要做什么?Action是框架里面的类吗?