那位jsp高手请伴我看看
各位大侠请帮我看看这个代码
jsp实现上传下载功能。
我的上传页面为fileUpload.jsp如下
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<html>
<head>
<title>文件上传测试</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center>
<form action="doFileUpload.jsp" method="post" enctype="multipart/form-data">
<table width="393" height="251" border="0" cellpadding="0" cellspacing="0">
<tr><td>软件名称</td><td><input type="text" name="name" id="name"/></td></tr>
<tr><td>软件版本</td><td><input type="text" name="version" id="version"/></td></tr>
<tr><td>软件大小</td><td><input type="text" name="size" id="size"/></td></tr>
<tr><td>软件语言</td><td><input name="lauguage" type="text" id="lauguage"/></td></tr>
<tr><td>软件类别</td><td><input name="type" type="text" id="type"/></td></tr>
<tr><td>运行环境</td><td><input name="run" type="text" id="run"/></td></tr>
<tr><td>加入时间</td><td><input name="time" type="text" id="time"/></td></tr>
<tr><td>升级内容</td><td><input name="content" type="text" id="content"/></td></tr>
<tr><td>下载须知</td><td><input name="request" type="text" id="request"/></td></tr>
<tr><td>安装注意</td><td><input name="attention" type="text" id="attention"/></td></tr>
<tr><td>软件介绍</td><td><input name="recommend" type="text" id="recommend"/></td></tr>
<tr><td>下载链接</td><td><input name="address" type="file" id="address"/></td></tr>
<tr><td colspan="2" style="text-align:center"><input type="submit" value="确定"/></td></tr>
</table>
</form>
</center>
</body>
</html>
处理上传页面为doFileUpload.jsp代码如下
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="com.jspsmart.upload.SmartUpload"%>
<%@ page import="electrictDao.*,electrictEntity.*" %>
<%@ page import="java.text.*" %>
<%
String name;
String version;
String size;
String time;
String type;
String requests;
String attention;
String address;
String recommend;
String run;
String lauguage;
String encodeFileName;
String content;
%>
<% SmartUpload su=new SmartUpload();
FileDao fileDao=new FileDao();
File file=new File();
int result=0;
try{
su.initialize(pageContext);
su.upload();
for(int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File files=su.getFiles().getFile(i);
if(!files.isMissing())
{
String path=getServletContext().getRealPath("/")+"upload\\";
String pre = "集成电路与应用网站"+new SimpleDateFormat("yyyyMMddhhmmss").format(new Date())+System.currentTimeMillis();
//文件扩展名
String ext = "."+files.getFileExt();
//文件名
encodeFileName = pre+ext;
//路径+文件名
String fileNameAndPath = path+encodeFileName;
//存储文件
files.saveAs(fileNameAndPath,su.SAVE_PHYSICAL);
//获取文件信息插入数据库
size=su.getRequest().getParameter("size");
version=su.getRequest().getParameter("version");
type=su.getRequest().getParameter("type");
requests=su.getRequest().getParameter("request");
recommend=su.getRequest().getParameter("recommend");
lauguage=su.getRequest().getParameter("lauguage");
run=su.getRequest().getParameter("run");
name=su.getRequest().getParameter("name");
time=su.getRequest().getParameter("time");
attention=su.getRequest().getParameter("attention");
content=su.getRequest().getParameter("content");
address=su.getRequest().getParameter("address");
file.setAttention(attention);
file.setContent(content);
file.setHref(address);
file.setLauguage(lauguage);
file.setName(name);
file.setRequest(requests);
file.setRecommend(recommend);
file.setRun(run);
file.setSize(size);
file.setTime(time);
file.setType(type);
file.setVersion(version);
file.setEncodeFileName(encodeFileName);
result=fileDao.addFile(file);
System.out.println("result="+result);
if(result!=0){
out.print("<script>alert('文件上传成功!');history.go(-1);</script>");
}
}
}
}catch(Exception ex){
out.print("<script>alert('文件上传失败!');history.go(-1);</script>");
}
%>
下载页面为fileDownload.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="electrictDao.*" %>
<%@ page import=" electrictEntity.*"%>
<html>
<head>
<title>→文件上传</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center>
<% FileDao fileDao=new FileDao();
List list=fileDao.getAll();
for(int i=0;i<list.size();i++)
{
File file=(File)list.get(i); %>
<div>
<table width="349" height="212" border="0" cellpadding="0" cellspacing="0" style="font-size:12px">
<tr><td>软件名称</td><td><%=file.getName() %></td></tr>
<tr><td>软件版本</td><td><%=file.getVersion() %></td></tr>
<tr><td>软件语言</td><td><%=file.getLauguage() %></td></tr>
<tr><td>软件类别</td><td><%=file.getType() %></td></tr>
<tr><td>运行环境</td><td><%=file.getRecommend() %></td></tr>
<tr><td>软件大小</td><td><%=file.getSize() %></td></tr>
<tr><td>加入时间</td><td><%=file.getTime() %></td></tr>
<tr><td>升级内容</td><td><%=file.getContent() %></td></tr>
<tr><td>下载须知</td><td><%=file.getRecommend() %></td></tr>
<tr><td>安装注意</td><td><%=file.getAttention() %></td></tr>
<tr><td>软件介绍</td><td><%=file.getRecommend() %></td></tr>
<tr><td>下载链接</td><td><a href="doFileDownload.jsp?fileName=<%=file.getEncodeFileName() %>"><%=file.getHref() %></a></td></tr>
</table>
</div>
<% } %>
</center>
</body>
</html>
下载处理页面为doFileDownload.jsp
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ page import="com.jspsmart.upload.SmartUpload"%>
<% SmartUpload su = new SmartUpload();
//request.setCharacterEncoding("GBK");
String fileName = request.getParameter("fileName");
try{
out.clear();//清空缓存的内容
/* 返回一个新的BodyContent(代表一个HTML页面的BODY部分内容)
保存JspWriter实例的对象out
更新PageContext的out属性的内容
*/
out = pageContext.pushBody();
//初始化上下文
su.initialize(pageContext);
su.setContentDisposition(null);
su.downloadFile("/upload/"+fileName);
}catch(Exception ex){
out.print("<script>alert('文件下载失败!');history.go(-1);</script>");
}
%>
问题解释点击下载页面的链接是没事出现下载界面。好像没甚么反应。小弟我做了好久。我是新手感慨是学习的,希望给为大虾帮我解决下。我的qq邮箱为903780652@qq.com