jsp写出一个私人网盘系统!从零开始![不使用任何现成的框架!]
注:这个和我写的一个用户系统是相结合的,注册时会自动创建用户文件夹!
ps:新人不宜QAQ,您大人有大量,点个赞吧!;w;
session属性:
name
level(其实没用)
class1(其实没用)
tell(其实没用)
z(其实没用)
效果图:
主体:
index.jsp - 负责显示和上传传递和下载
upload.jsp - 负责保存上传文件 (使用smartupload)
index.jsp源码:
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<html>
<head>
<meta charset="utf-8">
<title>YaoServer</title>
<link rel="icon" href="/photo/favicon2.png" type="image/x-icon">
<link href="/css/button.css" rel="stylesheet" type="text/css" />
<link href="/css/user.css" rel="stylesheet" type="text/css" />
<embed src="/music//china-x.mp3" hidden="true" autostart="true" loop="true">
<style>
.a-upload {
padding: 4px 10px;
height: 20px;
line-height: 20px;
position: relative;
cursor: pointer;
color: #888;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: inline-block;
*display: inline;
*zoom: 1
}
.a-upload input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
filter: alpha(opacity=0);
cursor: pointer
}
.a-upload:hover {
color: #444;
background: #eee;
border-color: #ccc;
text-decoration: none
}
.file {
position: relative;
display: inline-block;
background: #D0EEFF;
border: 1px solid #99D3F5;
border-radius: 4px;
padding: 4px 12px;
overflow: hidden;
color: #1E88C7;
text-decoration: none;
text-indent: 0;
line-height: 20px;
}
.file input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
}
.file:hover {
background: #AADFFD;
border-color: #78C3F3;
color: #004974;
text-decoration: none;
}
</style>
<script>
while (true){
ifdocument.οncοntextmenu=function(e) {
alert("请勿右键");
return false;
}
}
</script>
</head>
<body background="photo/background1.png">
<div class="top">
<ul>
<li>
<a href="http://www.yaoserver.xyz/"><img src="/photo/favicon21.png">
</li>
<li>
<a href="http://www.yaoserver.xyz/">主站</a>
</li>
<li>
<a href="#">§传送门§</a>
<ul>
<br>
<li><a href="https://www.microsoft.com//" target="_blank">Microsoft</a></li>
<li><a href="https://minecraft.net//" target="_blank">Minecraft官网</a></li>
<li><a href="https://bilibili.com//" target="_blank">Bilibili</a></li>
<li><a href="https://www.curseforge.com/minecraft/modpacks" target="_blank">curseforge</a></li>
</ul>
</li>
<li>
<a href="/user/">§用户§</a>
<ul>
<br>
<li><a href="/user/login.htm">登录</a></li>
<li><a href="/user/reg.htm">注册</a></li>
</ul>
</li>
<li>
<a href="#"> 搜索 </a>
<ul>
<div style="text-align: center;">
<a href="" class="baidulogo" target="_blank">
</a>
<input type="search" id="search_key">
<a class="size2" target="_blank" href="javascript:void(0)" onclick="butClick();">百度一下</a> </div>
</ul>
</li>
</div>
<br>
<br>
<br>
<br>
<div id="wrap">
</div>
<%
<%
String temp = (String)session.getAttribute("name");
String level = (String)session.getAttribute("level");
String z = (String)session.getAttribute("z");
String class1 = (String)session.getAttribute("class");
String tell = (String)session.getAttribute("tell");
String name = "您还未登录!";
if (!(z == "1") == false) {
name = temp;
if (class1.equals("Admin")) {
name = temp;
}
%>
%>
<p class="size3"> 欢迎来到您的私人网盘~</p>
<p class="size5"> 上传到这里的文件只有您能看见!</p>
<p class="size1"> 等级:<%=level%></p>
<%
try {
File file = new File(File.separator + "my" + File.separator + "website" + File.separator + "file" + File.separator + name + File.separator);
File result[] = file.listFiles();
for (int x = 0; x < result.length; x ++) {
String a2 = "" + result[x];
int beginIndex = a2.indexOf("//",a2.indexOf("file")) + 1;
String a3 = a2.substring(beginIndex);
a3 = a3.replaceAll("website","");
a2 = a2.replaceAll("my","");
a3 = a2.replaceAll("website","");
a3 = a3.replaceAll("//","");
String a4 = a3.replaceAll("txt","");
beginIndex = a4.indexOf("//",a4.indexOf("file")) + 1;
a4 = a4.substring(beginIndex);
beginIndex = a4.indexOf("//",a4.indexOf("file")) + 1;
a4 = a4.substring(beginIndex);
a4 = a4.replaceAll("user","");
a4 = a4.replaceAll(File.separator + name + File.separator + "file","");
a4 = a4.replaceAll("/","");
a4 = a4.replaceAll("file" + name,"");
a3 = "<a href=" + a3 + " download=" + a4 + ">" + a4 + "</a>";
%>
<br> <%=a3%><br>
<%
}
} catch (Exception e) {
}
}else{
%>
<center>
<br>
<a class = "size4" href="/user/login.htm">您还未登录!</a></br>
<a class = "size5" href="/user/login.htm">点击登录</a><br>
<a class = "size5" href="/user/reg.htm">点击注册</a>
</center>
<%
}
%>
</div>
<div class="centered">
<form action="upload.jsp" method="post" enctype="multipart/form-data">
请选择要上传的文件:<br><a href="javascript:;" class="file">选择文件<input type="file" class="a-upload" name="pic"></a>
<br><br><input type="submit" value="上传" class="small green button"></a>
<input type="reset" value="重置" class="small red button"></a>
</div>
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
</script>
</body>
</html>
upload.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="org.lxh.smart.*"%>
<%@ page import="java.lang.*"%>
<html>
<head><title>Yaoserver</title></head>
<body>
<%
SmartUpload smart = new SmartUpload() ;
smart.initialize(pageContext) ; // 初始化上传操作
smart.upload() ; // 上传准备
String name = smart.getRequest().getParameter("pic");
String temp = (String)session.getAttribute("name");
String filea = "/file/" + temp + "/";
smart.save(filea) ; // 文件保存
%>
<center>
<h1>上传成功~将会在3s内返回上传页面</h1>
</center>
<%
response.setHeader("Refresh","3;URL=/file");
%>
</body>
</html>
注意:
index.jsp中的那一长串是为了对/my/website/file/name属性/进行加工
使其仅有/file/name属性/(这个因人而异)!
smartupload.jar链接:
点击下载