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

📄 notepad.jsp

📁 简介:程序简介: 一个简单的记事本 可以标记5种主题的颜色 并采用txt存储数据 CSS无图片美化 只有一个页面 并可以任意修改.jsp前的名字
💻 JSP
📖 第 1 页 / 共 2 页
字号:
<%@ page contentType="text/html;charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<html>
<head>
<title>.::JSP Hi-Notepad::..::www.jsphi.com::.</title>
<style type="text/css">
<!--
table.tableborder{
border:1px dotted #999;
width:696;

filter:progid:DXImageTransform.Microsoft.Shadow(Color=#A5D8FF,Direction=120,strength=4)
}
table.tablebottomborder{

border:1px dotted #999;
width:696;
text-align:left;
}
b.rtop, b.rbottom{
display:block;background: #B0DCFD;
}
b.rtop2, b.rbottom2{
display:block;background: #ffffff;
}
b.rtop b, b.rbottom b{
display:block;height: 1px;overflow: hidden;filter:progid:DXImageTransform.Microsoft.Gradient
(startColorStr='#C3D82A', endColorStr='#9AB42A', gradientType='1');
}
b.rtop2 b, b.rbottom2 b{
display:block;height: 1px;overflow: hidden;filter:progid:DXImageTransform.Microsoft.Gradient
(startColorStr='#C3D82A', endColorStr='#9AB42A', gradientType='1');
}
b.r1{margin: 0 5px;}
b.r2{margin: 0 3px;}
b.r3{margin: 0 2px;}
b.rtop b.r4, b.rbottom b.r4{margin: 0 1px;height: 2px;}
b.rtop2 b.r4, b.rbottom2 b.r4{margin: 0 1px;height: 2px;}

b.middle{
	font-family:Arial Bold;
	font-size: 25px;
	height:88;
	font-weight: 900;
	color: #FFFFFF;
	}
body,td,th {
	font-size: 12px;
}
a:link {
	color: #0076CE;
}
a:visited {
	color: #0076CE;
}
a:hover{
color:#FF8F29;
}
-->
</style>
</head>
<body style="filter:progid:DXImageTransform.Microsoft.Gradient
(startColorStr='#ACDAFD', endColorStr='#FFFFFF', gradientType='0');" bgcolor="ACDAFD">
<center>
<div style="filter:progid:DXImageTransform.Microsoft.Gradient
(startColorStr='#C3D82A', endColorStr='#9AB42A', gradientType='1');height:88;width:710;border:0;
">
<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
   <b class="middle"><br>.::  JSP Hi-Notepad  ::.</b>
<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>
</div></center>
<p>
<%!String filePath;
String ThisFileName;
%>
<%filePath=request.getServletPath();
ThisFileName=filePath.replace("/","");
%>
<%!
	int k=0;
	File filedata,fileListCreator;
	boolean is_floder;
        String website_path;
        String data_path;
        boolean html_flag;
        %>
        <%
        website_path=application.getRealPath("");//获取当前文件所在的路径,从而方便在同一文件夹下创建数据文件
        website_path=website_path.replace("\\","\\\\");
         data_path=website_path+"\\JSPHI_data";/*注意相对路径目录由系统属性 user.dir 指定,通常是 Java虚拟机的调用目录。 */
         %>
        <%!
	File filerecord;
	FileReader recordReader;
	BufferedReader bufferedReader;
	String thisPageName=ThisFileName;
	String ID,changeTime,power,createTime,fileName,message,isHtml;
	/*开始:判断[数据文件夹]是否存在,不存在则创建*/
	public void setDataFolder(String data_path)
	{
		filedata=new File(data_path);
		is_floder=filedata.exists();//判断文件夹是否存在
		if(!filedata.exists())
		{
			is_floder=filedata.mkdir();//如果不存在则创建
		}
	}
        public void setFileList()
	{
          try{
            fileListCreator=new File(data_path+"\\fileList.txt");
              is_floder=fileListCreator.createNewFile();//如果不存在则创建
          }catch(Exception e){System.out.println(e);}
	}
	/*结束:判断数据文件夹data是否存在,不存在则创建*/
        /*开始:转码部分*/
	public String translate(String str)
	{
		try{
			byte b[]=str.getBytes("ISO-8859-1");
			str=new String(b);
		}catch(Exception e){System.out.println(e);}
		return str;
	}
	/*结束:转码部分*/
	/*开始:转码部分*/
        public String translate_html(String str)
        {
          html_flag=false;
          if(str.contains("<")&&(str.contains(">")))
          {
            html_flag=true;
          }
          if(str.contains("<"))
          {
            str=str.replaceAll("<","&lt;");
          }
          if(str.contains(">"))
          {
            str=str.replaceAll("<","&rt;");
          }
          if(str.contains("\n"))
          {
            str=str.replaceAll("\n","<br>");
          }
          if(str.contains(" "))
          {
            str=str.replaceAll(" ","&nbsp;");
          }
          try{
		byte b[]=str.getBytes("ISO-8859-1");
                str=new String(b);
              }catch(Exception e){System.out.println(e);}
              return str;
	}
	/*结束:转码部分*/
	/*开始:单个文件读取数据*/
	public void setFile(String recordName)
	{
	try{
		filerecord=new File(data_path+"\\"+recordName);
		recordReader=new FileReader(filerecord);
		bufferedReader=new BufferedReader(recordReader);
		String str=new String();
			while(bufferedReader.ready())
			{
				str+=bufferedReader.readLine();
			}
		int power_index=str.lastIndexOf("<power>")+7;//获取power头下标
		int power_lastindex=str.lastIndexOf("</power>");//获取power尾下标
		int createTime_index=str.lastIndexOf("<createTime>")+12;//获取changeTime头下标
		int createTime_lastindex=str.lastIndexOf("</createTime>");//获取changeTime尾下标
		int fileName_index=str.lastIndexOf("<fileName>")+10;//获取fileName头下标
		int fileName_lastindex=str.lastIndexOf("</fileName>");//获取fileName尾下标
		int message_index=str.lastIndexOf("<message>")+9;//获取message头下标
		int message_lastindex=str.lastIndexOf("</message>");//获取message尾下标
		power=str.substring(power_index,power_lastindex) ;//截取字符串并赋值
		createTime=str.substring(createTime_index,createTime_lastindex) ;
		String[] newCreateTime=createTime.split("-");
		String[] newCreateTime2=newCreateTime[2].split("_");
		createTime=newCreateTime[0]+"-"+newCreateTime[1]+"-"+newCreateTime2[0]+" "+newCreateTime2[1]+":"+newCreateTime[3]+":"+newCreateTime[4];       
		fileName=str.substring(fileName_index,fileName_lastindex) ;
		message=str.substring(message_index,message_lastindex) ;/*用不用buffered?*/
                recordReader.close();
		bufferedReader.close();
		}catch(Exception e){System.out.print(e);}
	}
	/*结束:单个文件读取数据*/
	/*开始:创建新记录*/
	public void createNewFile(String newFileName,String newFileTitle,String newFileMessage,String newPower)
	{
		try{
			File newFile=new File(data_path+"\\"+newFileName+".txt");
			newFile.createNewFile();
			FileWriter newFileWriter=new FileWriter(newFile);
			BufferedWriter newFileBWriter=new BufferedWriter(newFileWriter);
			newFileBWriter.write("<createTime>"+newFileName.trim()+"</createTime>");
			newFileBWriter.write("<power>"+newPower.trim()+"</power>");
			newFileBWriter.write("<isHtml>"+html_flag+"</isHtml>");
			newFileBWriter.write("<fileName>"+translate(newFileTitle.trim())+"</fileName>");
			newFileBWriter.write("<message>"+translate_html(newFileMessage.trim())+"</message>");
			newFileBWriter.close();
			File newfileList=new File(data_path+"\\fileList.txt");
			FileWriter newFileListWriter=new FileWriter(newfileList,true);
			BufferedWriter newFileListBWriter=new BufferedWriter(newFileListWriter);
			newFileListBWriter.write(newFileName+".txt");
			newFileListBWriter.newLine();
			newFileListBWriter.close();
		}catch(Exception e){System.out.println(e);}
	}
	/*结束:创建新记录*/
	/*开始:获取当前时间*/
	public String getNowTime()
	{
		Calendar rightNow = Calendar.getInstance();
		java.text.SimpleDateFormat instance = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
		String date = instance.format(rightNow.getTime());
		return date;
	}

⌨️ 快捷键说明

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