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

📄 softdownaction.jsp~43~

📁 使用J2EE实现了软件园的下载和上传功能
💻 JSP~43~
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.io.*"%>
<html>
<head>
<title>
软件园
</title>
<LINK href="css.css" type="text/css" rel="stylesheet">
</head>
<body bgcolor="#ffffff">
<%!
	public String codeString(String s){
		String str=s;
                try{
			byte b[]=str.getBytes("ISO-8859-1");
			str=new String (b);
			return str;
		}catch(Exception e){
			return "error";
		}
	}
%>
<%
	String dbPath=request.getParameter("dbPath");
        System.out.println(dbPath);
        //String dbSoftware=request.getParameter("dbSoftware");
        //System.out.println(dbSoftware);
        String dbSoftware=dbPath.substring(dbPath.lastIndexOf('\\')+1);
        System.out.println(dbSoftware);
	if(dbPath==null) dbPath="";
	if(!dbPath.equals("")){
		//dbPath=codeString(dbPath);
		//String dir="E:/Download/";
		//dir=dir+dbSoftware;
		try{    File file=new File(dbPath);
			if(file.isFile()&&file.exists()){
			  System.out.print("FileExist");
				OutputStream o=response.getOutputStream();
				FileInputStream in=new FileInputStream(file);
				byte b[]=new byte[1024];
                                dbSoftware=java.net.URLEncoder.encode(dbSoftware,"utf-8");//防止name含有中文的话,输出的文件名称会出现乱码
				response.setHeader("Content-disposition","attachment;filename="+dbSoftware);
				response.setContentType("application/x-tar");//配合web.xml里面的mime类型定义
				long filelength=file.length();
				String length=String.valueOf(filelength);
				response.setHeader("Content_Length",length);
				int n=0;
				while((n=in.read(b))!=-1){
					o.write(b,0,n);
				}
				in.close();
				o.close();
				out.print("over");;
			}
			else{
				out.print("文件不存在!");
			}
		}
		catch(IOException e){
			out.print("IOError!");
		}
	}
	else{
		//response.sendRedirect("downloadMain.jsp");
                out.print("<script language=JavaScript>alert('没有此软件,请返回');");
                out.print("javascript:history.go(-1);</script>");
	}
 %>
</body>
</html>
<%--
try {      request.setCharacterEncoding("gb2312");
            javax.naming.Context ic = new javax.naming.InitialContext();
            Object obj = ic.lookup("softwareRemote");
            software.softwareRemoteHome home = (software.softwareRemoteHome) javax.rmi.
                                  PortableRemoteObject.narrow(obj,
                    software.softwareRemoteHome.class);
            java.util.Collection c=home.getTypes();
            java.util.Iterator i=c.iterator();
            while(i.hasNext()){
            String type=i.next().toString();
            type=new String(type.getBytes("iso8859-1"),"gb2312");
            out.println(type);
        }} catch (Exception ex) {
            ex.printStackTrace();
        }
--%>

⌨️ 快捷键说明

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