首页 > 编程 > JSP > 正文

,JSP如何实现文件上传

2019-11-02 14:23:21
字体:
来源:转载
供稿:网友

  程序如下:

  package linkman.helper;

  import java.io.*;

  import java.util.*;

  import javax.servlet.http.HttpServletRequest;

  import javax.servlet.http.HttpServletResponse;

  import javax.servlet.ServletInputStream;

  public class UpLoadBean {

  private String SavePath = null;

  private String FileName = null;

  private String Sperator = null;

  private String ErrMsg = "正常返回";

  private byte[] bt = new byte[4096];

  private byte[] prebt = new byte[4096];

  private int t = -1;

  private long FileSize = -1;

  private boolean UserDefineFileName = false;

  /////////////////////////////////////////////////

  public UpLoadBean () {

  FileName = bringFileName ();

  }

  public UpLoadBean (String savepath) {

  SavePath = savepath;

  FileName = bringFileName ();

  }

  /////////////////////////////////////////////////

  // 文件名信息

  private String bringFileName () {

  Calendar dt = Calendar.getInstance ();

  String str = "" + dt.get (Calendar.YEAR) + dt.get (Calendar.MONTH) + dt.get (Calendar.DAY_OF_MONTH);

  str = str + dt.get (Calendar.HOUR) + dt.get (Calend

十个字网名[www.la240.com/html2017/1/27/]
ar.MINUTE) + dt.get (Calendar.SECOND);

  return str;

  }

  public void setFileName (String filename) {

  FileName = filename;

  UserDefineFileName = true;

  }

  public String getFileName () {

  return FileName;

  }

  /////////////////////////////////////////////////

  // 上传文件主程序

  public boolean UpLoad (HttpServletRequest request) throws Exception {

  if (SavePath == null) {

  setErrorMessage ("未设置保存上传文件的路径");

  return false;

  }

  request.setCharacterEncoding("utf-8");

  ServletInputStream in = request.getInputStream ();

  ////////////////////////////////////////////

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表