用JSP下载word文件
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
String filename = "";
if (request.getParameter("file") != null) {
filename = request.getParameter("file");
}
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename="+filename);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(final IOException e) {
System.out.println ( "出现IOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
return;
%>
详细出处参考:http://www.jb51.net/article/2631.htm
相关文档:
一般,在很多应用系统中,用户多次提交重复数据是一个很严重的问题,会导致应用系统中很多垃圾数据,在Struts中框架中,有TOKEN机制来防止用户提交重复数据,这是一个很好的办法,但是,TOKEN机制必须得用到html:form标签,我不喜欢用这个标签,我觉得是一个累赘,所以我去掉HTML:FORM标签,重新定义TOK ......
JSP/Servlet转发与重定向的区别
尽管HttpServletResponse.sendRedirect 方法和RequestDispatcher.forward 方法都可以让浏览器获得另外一个URL所指向的资源,但两者的内部运行机制有着很大的区别。
下面是HttpServletResponse.sendRedirect 方法实现的请求重定向与RequestDispatcher.forward 方法实现的请求 ......
jsp中include的两种形式: 1.<%@ include file=” ”%>
&nbs ......
选题依据及研究意义
现代物流,是指产品从生产地到消费地之间的整个供应链,运用先进的组织方式和管理技术,进行高效率计划、管理、配送链,为用户提供多功能、一体化的综合性服务,从而达到降低流通成本、提高生产效率、增加企业利润。的新型服务业。它通过对运输、仓储、装卸、加工、整理、配送与信息等方面有机结合,形 ......
首先是提交页面:三个表单(form1,form2,form3)
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
&nb ......