当前位置:首页 > Linux下J2EE开发与运行环境搭建达到JSP程序可以访问数据库 - 图文
上海商学院Linux操作系统课程设计报告
public void destroy() { super.destroy(); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SmartUpload andy = new SmartUpload(); andy.initialize(config, request, response); try {
andy.setDenyPhysicalPath(true); // 拒绝物理路径
andy.setMaxFileSize(5000000);// 设置允许上传文件最大为50000bytes
andy.setTotalMaxFileSize(50000000);// 一次上传文件大小最多不超过5000000bytes andy.upload();
for (int i = 0; i < andy.getFiles().getCount(); i++) {
com.jspsmart.upload.File myfile = andy.getFiles().getFile(i); response.setContentType(\ PrintWriter out = response.getWriter();
String UpId= andy.getRequest().getParameter(\
String UpName= andy.getRequest().getParameter(\
String CourseName= andy.getRequest().getParameter(\ String FileName=myfile.getFileName(); andy.save(\
out.print(\上传者编号: \ out.print(\上传者姓名: \ out.print(\文件名: \ out.print(\课程名: \ out.print(\文件上传成功!\ andy dosql=new andy();
dosql.addfile(UpId,UpName,CourseName,FileName);
response.sendRedirect(\如果要显示上传情况,可以将此句注释掉 out.close(); }
} catch (Exception e) { e.printStackTrace();
- 21 -
Linux下J2EE开发与运行环境搭建达到JSP程序可以访问数据库
} }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
public void init(ServletConfig config) throws ServletException { this.config = config; } }
6.6.2.1 下载代码
DownloadServlet.java package servlet; import java.io.*;
import javax.servlet.*; import javax.servlet.http.*; import com.jspsmart.upload.*;
public class DownloadServlet extends HttpServlet { private ServletConfig config;
public DownloadServlet() { super(); }
public void destroy() { super.destroy(); }
public void doPost(HttpServletRequest request, HttpServletResponse response)
- 22 -
上海商学院Linux操作系统课程设计报告
throws ServletException, IOException {
SmartUpload andy = new SmartUpload(); //新建一个SmartUpload对象 andy.initialize(config, request, response); try {
response.setContentType(\ request.setCharacterEncoding(\
String name=new String(request.getParameter(\
andy.setContentDisposition(null);//如果要实现单击在浏览器打开,注释该即可.
andy.downloadFile(\下载目录
} catch (SmartUploadException e) { e.printStackTrace(); } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
public void init(ServletConfig config) throws ServletException { this.config = config; } }
6.6.2.3 删除功能代码
delete.jsp
<%@ page language=\
- 23 -
Linux下J2EE开发与运行环境搭建达到JSP程序可以访问数据库
<% andy dosql=new andy();
String FileName=request.getParameter(\ response.setHeader(\\java.net.URLEncoder.encode(FileName, \ if(FileName!=null)
dosql.deletefileByFileName(FileName); response.sendRedirect(\ %>