One: Get file path
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>my JSP ' getpath.jsp ' starting page</title>
<body>
<%
String Path=application.getrealpath ("/");
%>
</body>
Two: Get the input content
<% @page import= "java.io.*"%>
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>my JSP ' input_content.jsp ' starting page</title>
<body>
<form action= "input_content.jsp" method= "POST" >
Input file name: <input type= "text" name= "filename" ><br>
Input file contents: <textarea name= "Filecontent" rows= "2" cols= "></textarea><br>"
<input type= "Submit" value= "Submission" >
<input type= "reset" value= "reset" >
</form>
<%
Request.setcharacterencoding ("Utf-8");
String name=request.getparameter ("filename");
String content=request.getparameter ("filecontent");
String Filename=this.getservletcontext (). Getrealpath ("/")
+ "Note" +file.separator+name;
File File=new file (fileName);
Determine if a parent folder exists
if (!file.getparentfile (). exists ()) {
File.getparentfile (). mkdir ();
}
PrintStream Ps=null;
Ps=new PrintStream (new FileOutputStream (file));
PS.PRINTLN (content);
Ps.close ();
%>
<%
Read content
Scanner scan=new Scanner (new FileInputStream (file));
Scan.usedelimiter ("\ n");
StringBuffer buf=new StringBuffer ();
while (Scan.hasnext ()) {
Buf.append (Scan.next ()). Append ("<br>");
}
Scan.close ();
%>
<%=buf%>
</body>
Three: Website counter
<% @page import= "Java.io.FileOutputStream"%>
<% @page import= "Java.io.PrintStream"%>
<% @page import= "Java.io.FileInputStream"%>
<% @page import= "javax.servlet.jsp.tagext.TryCatchFinally"%>
<% @page import= "Java.io.File"%>
<% @page import= "Java.math.BigInteger"%>
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>my JSP ' count.jsp ' starting page</title>
<body>
<%!//Defining a global variable
BigInteger Count=null;
%>
<%!
Reading a Count file
Public BigInteger Load (file file) {
Receive the Read data
BigInteger Count=null;
try{
if (file.exists ()) {
Scanner Scan=null;
Scan=new Scanner (new FileInputStream (file));
if (Scan.hasnext ()) {
Count=new BigInteger (Scan.next ());
}
Scan.close ();
}else{
First time visit
Count=new BigInteger ("0");
Save (File,count);
}
}catch (Exception e) {
E.printstacktrace ();
}
return count;
}
public void Save (File File,biginteger count) {
try{
PrintStream Ps=null;
Ps=new PrintStream (new FileOutputStream (file));
Ps.println (count);
Ps.close ();
}catch (Exception e) {
E.printstacktrace ();
}
}
%>
<%
String Filename=this.getservletcontext (). Getrealpath ("/") + "count.txt";
File File=new file (filename);
if (Session.isnew ()) {
Synchronized (this) {
Count=load (file);
Count=count.add (New BigInteger ("1"));
Save (File,count);
}
}
%>
</body>
Four: viewing attribute ranges
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>my JSP ' application.jsp ' starting page</title>
<body>
<%
Enumeration Enu=this.getservletcontext (). Getattributenames ();
while (Enu.hasmoreelements ()) {
String Name= (String) enu.nextelement ();
%>
<%
}
%>
</body>
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
JSP built-in Objects (iii): Application