Append to jsp file operations _ MySQL

Source: Internet
Author: User
File operations are an important part of website programming. asp has discussed a lot about file operations. let's take a look at how jsp is implemented. Two files are used here. one jsp file and one javabean file can be easily appended to a text file by calling javabean in jsp. if you read the previous article, it will be found that this article has a lot of file operations as one of the important content of website programming, and asp has discussed a lot about file operations. let's take a look at how jsp is implemented.
Two files are used here. one jsp file and one javabean file can be easily appended to a text file by calling javabean in jsp. if you read the previous article, we will find that this article has many similarities with the previous article and it is easy to read.
Please put afile.txt in the directory test of the web root directory so that the program can append data. after compiling the javabean file, place the class file in the corresponding class directory (tomcat environment ).

WriteAppend. jsp



Append data


<% -- Create a javabean and set properties -- %>





Append data


<% -- Set the string to be appended -- %>
<% Writer. setSomething ("append data"); %>
<% -- Read the string set above -- %>
<% Out. print (writer. getSomething (); %>
<% -- Call writer's writeSomething method to append the file and return the success or error message -- %>
<% Out. print (writer. writeSomething (); %>





// WriteAppend. java javabean file
Import java. io .*;

Public class WriteAppend {

Private String path; // file path
Private String something; // Append String variable
// Initialization
Public WriteAppend (){
Path = null;
Something = "Default message ";
}
// Set the file path
Public void setPath (String apath ){
Path = apath;
}
// Obtain the file path
Public String getPath (){
Return path;
}
// Set the string to be appended
Public void setSomething (String asomething ){
Something = asomething;
}
// Obtain the string to be appended
Public String getSomething (){
Return something;
}
// Append the string
Public String writeSomething (){
Try {
// Create the file path and write the something string. Note the difference between the path and the writing.
FileWriter theFile = new FileWriter (path, true );
PrintWriter out = new PrintWriter (theFile );
Out. print (something +"
");
Out. close ();
// Close the file and return the success string
TheFile. close ();
Return "success !! ";
} Catch (IOException e ){
Return e. toString ();
}
}
}

All right, all the operations on this file have been completed. if you see this, I believe you are OK with the basic operations on the file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.