用Jsp来实现文件下载功能的几种方式
1.最直接最简单的,方式是把文件地址直接放到html页面的一个链接中。这样做的缺点是把文件在服务器上的路径暴露了,并且还无法对文件下载进行其它的控制(如权限)。这个就不写示例了。
2.在服务器端把文件转换成输出流,写入到response,以response把文件带到浏览器,由浏览器来提示用户是否愿意保存文件到本地。(示例如下)
<%
response.setContentType(fileminitype);
response.setHeader("Location",filename);
response.setHeader("Cache-Control", "max-age=" + cacheTime);
//filename应该是编码后的(utf-8)
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setContentLength(filelength);
OutputStream outputStream = response.getOutputStream();
InputStream inputStream = new FileInputStream(filepath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();
inputStream.close();
outputStream = null;
%>
3.既然是JSP的话,还有一种方式就是用Applet来实现文件的下载。不过客户首先得信任你的这个Applet小程序,由这个程序来接受由servlet发送来的数据流,并写入到本地。
servlet端示例
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType(" text/plain ");
OutputStream outputStream = null;
try {
outputStream = res.getOutputStream();
//把文件路径为srcFile的文件写入outputStream中
popFile(srcFile, outputStream)) ;
} catch (IOException e) {
e.printStackTrace();
}
}
JApplet端示例
URLConnection con;
try {
//url是被调用的SERVLET的网址 如 *.do
con = url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProper
相关文档:
有两种传参方式
一、get方式:
这种方式将参数写在url中,举例来说,如果目标传参页面是target.jsp,那么在url里可以这么写:
http://..../target.jsp? <Param1> = <value1> & <Param2> = <value2> &...
&n ......
<body style="height:100%;">
-------------------------------------------------------------------一开始的页面----------------------
fdasfsdfadf
<input name="button2" onclick="ShopConfirm('fdsaf')" value="点我" type="button"/>
--------------------------------------------------------- ......
FCKeditor jsp 配置 使用
2009-04-07 16:57
FCKeditor是一款跨平台的在线编辑器,到我发布本文,FCKeditor的官方版本已经发展到了2.6.4
点击进入 官网
1、首先登陆www.fckeditor.net/download下载FCKeditor的最新版本,需要下载2个压缩包,一个是基本应用,另一个是在为在jsp下所准备的配置。
  ......
建立条件首先一定要确定自己的mysql,tomcat,eclipse连接是正确的。
index.jsp很简单,就一个跳转。
<%
response.sendRedirect("lg.jsp");
%>
lg.jsp 实现登录框架
<%@ page contentType="text/html; charset=utf-8" %>
<html>
<head>
<title>
login
</title>
</hea ......
方法一、
login.html
<html>
<head>
<title>用户登录</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<script language="javascript">
&nbs ......