⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedownloadservlet.java~23~

📁 c++通信编程学习1
💻 JAVA~23~
字号:
package com.j2ee.servlet.first;
import com.j2ee.servlet.first.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class FiledownloadServlet extends commServlet {
    private static final String CONTENT_TYPE = "text/html; charset=GBK";
    private File f1;
    private RandomAccessFile f2;
    private FileInputStream is;
    public FiledownloadServlet() {
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doService(request,response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    //所有来自request请求方法归类到下面方法中
    public void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
 //       PrintWriter out = response.getWriter();
       HttpSession session=request.getSession();
        ServletOutputStream outStream = response.getOutputStream();
        String lm=(String)session.getAttribute("lm");
        String filename=request.getParameter("name");
        String rightf=filename.substring(filename.length()-4);
        String ContentType=new String();
         FileInputStream is;
        ServletContext app=this.getServletContext();
        int flsize=0;
        if(rightf.equals("")){

        }else if(rightf.equals( ".asf")){
           ContentType = "video/x-ms-asf";
          }else if(rightf.equals( ".avi")){
           ContentType = "video/avi";
          }else if(rightf.equals( ".doc")){
           ContentType = "application/msword";
          }else if(rightf.equals( ".zip")){
           ContentType = "application/zip";
          }else if(rightf.equals( ".xls")){
           ContentType = "application/vnd.ms-excel";
          }else if(rightf.equals( ".gif")){
           ContentType = "image/gif";
          }else if(rightf.equals( ".jpg")||rightf.equals("jpeg")){
           ContentType = "image/jpeg";
          }else if(rightf.equals( ".wav")){
           ContentType = "audio/wav";
          }else if(rightf.equals( ".mp3")){
           ContentType = "audio/mpeg3";
          }else if(rightf.equals( ".mpg")||rightf.equals("mpeg")){
           ContentType = "video/mpeg";
          }else if(rightf.equals( ".rtf")){
           ContentType = "application/rtf";
          }else if(rightf.equals( ".htm")||rightf.equals( "html")){
           ContentType = "text/html";
          }else if(rightf.equals( ".txt")){
           ContentType = "text/plain";
          }else {
           ContentType = "application/octet-stream";
          }
          response.setContentType(ContentType);
        if(lm.equals("ydm")){
            filename="../j2eemanage/upload/ydm/"+filename;
            filename=app.getRealPath(filename);
        }
        if(lm.equals("sj")){
            filename="../j2ee/upload/sj/"+filename;
            filename=app.getRealPath(filename);
        }
        if(lm.equals("yy")){
            filename="../j2ee/upload/yy/"+filename;
            filename=app.getRealPath(filename);
        }
        f1=new File(filename);
        f2=new RandomAccessFile(f1,"r");
        flsize=(int)f2.length();
        byte []bb=new byte[flsize];
        f2.read(bb);

        outStream.write(bb);
        outStream.close();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -