大神帮我看看这段代码什么意思

大神帮我看看这段代码什么意思


package control;

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.net.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(sb.toString()   
		         .getBytes(),   "ISO8859-1"));
	} catch (UnsupportedEncodingException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	 String filename = request.getParameter("filename");
	  if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0){
	     try {
			filename = new String(filename.getBytes("gb2312"), "ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
	 else 
	      if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
	           try {
				filename = URLEncoder.encode(filename, "gb2312");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				 
			}
	      }
	 response.setContentType("text/plain");
	 response.setHeader("Location",filename);
	 response.reset();
	 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 File(request.getRealPath("/upfile/")+"/"+filename);
				   //System.out.println(f);
				   bis = new BufferedInputStream((InputStream)new FileInputStream(request.getRealPath("/upfile/")+"/"+filename));
				    fos = response.getOutputStream();
				    bos = new BufferedOutputStream(fos);

				    int bytesRead = 0;
				    byte[] buffer = new byte[5 * 1024];
				    while ((bytesRead = bis.read(buffer)) != -1) {
				     bos.write(buffer, 0, bytesRead);
				    }
				    bos.close();
				    bis.close();
				    fos.close();
			
	               new Info().delPic(request.getRealPath("/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
}

}

微信扫码订阅
UP更新不错过~
关注
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要成为Python大神,需要掌握Python编程语言的基本语法和概念,理解面向对象编程思想,了解Python标准库及其常用模块,熟练使用Python编写程序解决实际问题。 以下是一些具体的建议,可以助你在成为Python大神的道路上取得进展: 1. 学习Python基础知识。首先要了解Python的基本语法和控制结构,理解变量、数据类型、函数和模块等概念,以及常见的Python内置函数和异常处理。 2. 实践编程。在掌握基础知识的同时,要不断地练习编写Python程序,通过实践来巩固和深化对语言的理解。 3. 学习面向对象编程。Python是一门面向对象的编程语言,掌握面向对象编程思想是成为Python大神的必备技能。 4. 学习Python标准库及其常用模块。Python标准库是Python编程的重要组成部分,掌握标准库及其常用模块可以提高Python编程的效率。 5. 学习第三方库和框架。Python拥有丰富的第三方库和框架,例如NumPy、Pandas、Django等,学习这些库和框架可以提高Python应用开发的能力。 6. 参与开源项目。参与开源项目可以锻炼自己的编程能力,同时也可以学习其他开发者的经验和技巧。 7. 不断学习和探索。Python语言和生态系统都在不断发展和壮大,成为Python大神需要不断学习和探索新的技术和工具。 总之,成为Python大神需要不断学习和实践,并积累经验和技能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值