import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import util.Info;
public class Upload extends HttpServlet {
/*** Constructor of the object.对象的构造函数*/
public Upload() {super();
}/*** Destruction of the servlet. <br>*/
public void destroy() {super.destroy(); // Just puts "destroy" string in log 只需在日志中输入“destroy”字符串即可// Put your code here
}/*** The doGet method of the servlet. <br>** This method is called when a form has its tag value method equals to get.* * @param request the request send by the client to the server* @param response the response send by the server to the client* @throws ServletException if an error occurred* @throws IOException if an error occurred*/
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);
}/*** The doPost method of the servlet. <br>** This method is called when a form has its tag value method equals to post.* * @param request the request send by the client to the server* @param response the response send by the server to the client* @throws ServletException if an error occurred* @throws IOException if an error occurred*/
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {StringBuffer sb = new StringBuffer(50); response.setContentType("application/x-msdownload;charset=GB2312"); try {response.setHeader("Content-Disposition", new String() .getBytes(), "ISO8859-1"));} catch (UnsupportedEncodingException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}String filename = Parameter("filename");if (Header("User-Agent").toLowerCase().indexOf("firefox") > 0){try {filename = new Bytes("gb2312"), "ISO8859-1");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}}else if (Header("User-Agent").toUpperCase().indexOf("MSIE") > 0){try {filename = de(filename, "gb2312");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch block}}response.setContentType("text/plain");response.setHeader("Location",filename);set();response.setHeader("Cache-Control", "max-age=0" );response.setHeader("Content-Disposition", "attachment; filename=" + filename);try {BufferedInputStream bis = null;BufferedOutputStream bos = null;OutputStream fos = null;// File f = new RealPath("/upfile/")+"/"+filename);//System.out.println(f);bis = new BufferedInputStream((InputStream)new RealPath("/upfile/")+"/"+filename));fos = OutputStream();bos = new BufferedOutputStream(fos);int bytesRead = 0;byte[] buffer = new byte[5 * 1024];while ((bytesRead = ad(buffer)) != -1) {bos.write(buffer, 0, bytesRead);}bos.close();bis.close();fos.close();new Info().RealPath("/upfile/")+"/", filename);} catch (Exception e) {}finally{}
}/*** Initialization of the servlet. <br>** @throws ServletException if an error occurs*/
public void init() throws ServletException {// Put your code here
}
}
本文发布于:2024-02-04 23:08:01,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170718483760610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |