A little summary of the press release

Source: Internet
Author: User

After a period of study, completed the basic functions of the press release, a little summary, convenient for future review. Here is my little summary, the shortcomings do not laughed at ...

We want to complete a press release, first of all to enable it to publish successfully, and to enable it to add, delete, modify, query, upload, download and other functions.
We also call Ajax features to see the output as XML, in JSON format, in news content. To complete the above functions, we will first install and configure the JDK, Tomcat, and Eclipse.
1. Installation and configuration of each software
1.1. Installation and configuration of JDK:
1.1.1, download jdk::http://www.oracle.com/technetwork/java/javase/downloads/index.html
1.1.2, installing JDK: Installing Jdk.exe
1.1.3, configure environment variables: Right-click "My Computer"-"advanced"-"Environment variables"
1) Create a new "java_home" variable in the system variable, the value of the variable is: C:\Program files\java\jdk (fill in according to your own installation path)
2) New "CLASSPATH" variable, the value of the variable is:.; %java_home%\lib;%java_home%\lib\tools.jar (in the variable value ".") is indispensable)
3) Add the variable value in the path variable (existing without new):%java_home%\bin;%java_home%\jre\bin (Note the ";" between the variable values) Separated
1.1.4, test: "Start"-"Run"-enter "Javac" and "enter" if you can print the usage instructions successfully!
1.1.5 to supplement environment variables:
1) Installation path of JAVA_HOME:JDK
2) Classpath:java load Classpath, only the class is recognized in the Java command in CLASSPATH, and a "." is added before the path. Represents the current path.
3) Path: The system can identify the Java,javac command under any path.
1.2. Tomcat installation and configuration: {The function of its various folders}:
1.2.1, tomcat acquisition and installation: Apache official website Download (http://tomcat.apache.org/), there are two different downloads, one is a normal installation version, one is to unzip the installation version. It's the same, but there are some interfaces in the normal installation that provide quick settings for Tomcat, and a normal installation will register Tomcat as a system service.
Tomcat Startup is a bat file (under Windows), in the Bin directory. You can double-click. If the startup is unsuccessful, the general situation is that the console comes out immediately and disappears, indicating that Tomcat did not find the Java Runtime environment. The simple understanding is that Tomcat cannot find the JDK and is not able to run.
1.2.2, Tomcat build: In the Java_home variable (created when JDK is configured), point to the JDK installation directory. Launch Tomcat, enter http://localhost:8080/in the browser address bar if you see a description of the Tomcat Introduction to God horse, the configuration is successful.
The directory structure of 1.2.3, Tomcat: The bin directory holds some executable programs and related content that start running Tomcat.
Conf stores the global configuration about the Tomcat server.
The Lib directory holds the jar packages required for Tomcat to run or the site to run, and all the sites on this Tomcat share these jar packages.
The WebApps directory is the default site root directory and can be changed.
The work directory is used for excessive resources when the server is running, simply to store the JSP, servlet translation, and compiled results.
The common folder is a public jar package.
The logs folder is primarily a log file.

1.1.4, other more detailed introduction: (http://www.cnblogs.com/Johness/archive/2012/07/20/2600937.html)
1.3. Installation and configuration of Eclipse:
1.3.1, download eclipse: (http://www.eclipse.org/downloads/)
1.3.2, Eclipse Configuration:
1) Configure JDK: Click "Window"--"preferences"--"Java"--"Installed JREs"
2) Configure Tomcat: Click "Window"--"preferences"-"Server"-"Runtime Environment"-"ADD"
2, the realization of each function
2.1. Connect to the database:
Multiple functions need to be connected to the database, we create a tool to connect to the database (util), named "Sqlserverconnectiont".
1) Loading the JDBC driver
Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
2) Create a database connection
Connection conn = drivermanager.getconnection ("jdbc:sqlserver://localhost:1433; Databasename=test1 "," sa "," sd951208 ");
The JDBC Connection common database and basic curd can be referenced (http://www.360doc.com/content/16/0816/17/35826655_583667086.shtml).
2.2, Javabeen:
Create "*.java" to add attributes such as ID, b_id, title, content, author, time, area, FileName, filecontent, and so on.
Right-click on the "source"/"Generate getter and Setter" menu item in the pop-up menu.
In the Generate Getter and Setter dialog box that pops up, click the Select All button and leave the default values for the other options.
Click the "OK" button to generate the properties of the GetXXX () and the Setxxx () method.
2.3, the press release (ADD):
When publishing news, fill in the various properties of the news to publish. The JSP page submits the data to the servlet processing, and the SQL statement insert is stored into the database. Where the date attribute uses the My97datepicker plugin, the introduction uses the TEXTAREA tag and the CKEditor plugin.
2.3.1, My97datepicker plug-in
Download the My97datepicker plugin (http://download.csdn.net/detail/emoven/8249073).
Introduce this component in the page JS file: <script type= "Text/javascript" src= "/test/my97datepicker/wdatepicker.js" ></script>
When adding a date, <input id= "1" type= "text" name= "Time" class= "Wdate" onfocus= "Wdatepicker ({datefmt: ' YyyyMMdd HH:mm:ss ', Isshowclear:false,readonly:true}) ">
Other more detailed calls to the official website view (http://www.my97.net/dp/demo/index.htm).
2.3.2, CKEditor plug-in
Download the CKEditor plugin (http://ckeditor.com/download).
Introduction of CKEditor Core file ckeditor.js <script type= "Text/javascript" src= "ckeditor/ckeditor.js" in page When using the editor, textarea rows= "ten" cols= "Name=" textarea1 "class=" CKEditor "> Introduction content </textarea>
2.4. Delete:
The JSP display page submits the data ID to be deleted through the hyperlink to the servlet processing, invoking the SQL statement Delete to remove the corresponding data. Transaction processing is used here to avoid deleting the book information when the attachment of the book is not deleted.
A detailed usage method for simple transactions (http://blog.sina.com.cn/s/blog_4b5bc0110100h0wz.html).
2.5. Modification:
Depending on the ID, the query's servlet invokes the SQL statement select to query out the news data and display it on the modified JSP page. The modified data is then sent to the modified servlet to invoke the SQL statement insert to store the data in the database.
2.6. Enquiry:
According to the ID, keyword, date and other requirements to query the news data, the JSP page sent to the servlet processing call SQL statement Select query out the news data.
In order for the query data to be displayed, it will be required to be displayed together on the page: the JSP display page String id = (string) request.getattribute ("id"); if (id = = NULL) {id = ""; Request.removeattribute ("id"); In servlet processing, get requirements: String id = request.getparameter ("id"); if (Id! = NULL &&!) Id.equals ("")) {SQL1 + = "and id_=?";} Then if (Id! = NULL &&!) Id.equals ("")) {ps1.setstring (I, Id); i++; System.out.println ("Id" +id); }
2.7. Upload:
Upload attachments to the JSP publishing page, differentiate the attachment data from other data through the servlet processing analysis, and then insert the SQL statement into the database by calling it.
1) Uploading attachments requires the use of Commons-fileupload.jar and Commons-io.jar two packs.
2) file upload must meet the criteria: The page form method must be post, because get transmitted data is too small, the page form enctype must be multipart/form-data type; The form provides an upload input field
3) The specific code can be referenced (http://blog.csdn.net/ajun_studio/article/details/6639306).
2.8. Download:
First, the ID of the attachment to be downloaded by the hyperlink is sent to the servlet processing, the SQL statement select queries out the attachment name and the attachment contents, and then the attachment is downloaded via Servletoutputstream and InputStream and byte b[].
The specific code can be referenced (http://blog.csdn.net/doymm2008/article/details/5630814).
2.9, Chinese characters garbled:
Method One: Tomcat's self-coding is iso-8859-1 format, is incompatible with the Chinese encoding. Resp.setcontenttype ("Text/html;charset=utf-8");//Set the character encoding of the page, solve the problem that the interface displays Chinese garbled characters
Method Two: Req.setcharacterencoding ("Utf-8");//must be written in the first place, because this way to read the data, otherwise the data will be wrong.
Method Three: Modify the configuration file. which is the Web. xml file
More detailed method reference (http://www.jb51.net/article/74710.htm or http://blog.sina.com.cn/s/blog_675e9aeb0101357h.html).
2.10, special character escapes:
String temp = News.getarea ();//Gets the content to be escaped
if (temp! = null) {//content cannot be empty
temp = Temp.replaceall ("<", "&lt;"); /Escape Special symbol "<" to "&lt;"
temp = Temp.replaceall (">", "&gt;"); /Escape Special symbol ">" to "&gt;"
temp = Temp.replaceall ("&", "&amp;"); /Escape Special symbol "&" to "&amp;"
temp = Temp.replaceall ("" "," &quot; "); /Escape Special symbol "" "to" &quot; "
temp = Temp.replaceall ("", "&nbsp;"); /Escape Special symbol "" to "&nbsp;"
News.setarea (temp);
}
Other ways can be consulted (http://blog.csdn.net/songlixing/article/details/6957902).
2.11, let CKEditor support JSP upload pictures
The idea is: 1) prepare the JSP upload file jar package: Commons-fileupload.jar and Commons-io.jar;2) write a JSP to receive the uploaded file (in addition to the upload image function, need to call a core JS statement); 3) Write a JSP for browsing the file (in addition to the upload image function, you need to call a core JS statement); 4) Modify the config.js of the CKEditor, and configure the JSP to upload the file and browse the file.
The specific code can be referenced (http://www.cnblogs.com/hannover/archive/2011/07/29/2121536.html).
2.12. Pagination Display
Define the variable pageSize (how many variables per page, user specified), Pagenow (want to show page number, user specified), PageCount (how many pages are in total, calculation: if (rowCount% pageSize = = 0) {PageCount = Rowcount/pagesize; } else {PageCount = (rowcount/pagesize) + 1;}), RowCount (total number of variables, by query).
RowCount query: SELECT COUNT (id_) from news;
Show select top "+ pageSize +" * FROM news where id_ not in (select Top "+ (PageSize * (pageNow-1)) +" Id_ from news Ord ER by id_ desc) Order BY id_ Desc
Design home, previous page, hyperlink jump, next page, end, direct jump xx page.
Detailed code can be consulted (http://www.cnblogs.com/yony/archive/2012/06/15/2550607.html).
2.13. check box
Set the check box for the property, you can do multiple selection, select All to operate, you can manipulate more than one data. JS function is used here. The type of the check box type= "checkbox". Ideas are as follows:
1) Set all the name values in the foreground JSP page to be the same as the checkbox you want to use.
2) use an array to get the parameters in the background.
3) make the necessary format conversion for the array, and then perform the SQL operation.
Code reference (Idea: http://www.cnblogs.com/haore147/p/3617968.html | check box settings: http://bbs.csdn.net/topics/350072249 | Reference instance: HTTP ://zhidao.baidu.com/link?url=y2gfibuhciuift_2iqzsmtqhfejgyo6_ WYH9PBE-A4Z5CZK4JBY9DSO08MOPBVOBNP1S4-SY3WHE8UF9WBR8YVQQOS4XKPT0SOAGJQEN02E)
3. AJAX Features
3.1. Output xml:
When the user clicks on the "Get LIST Info" button above, the Loadxmldoc () function is executed. The Loadxmldoc () function creates a XMLHttpRequest object, adds a function that executes when the server responds in readiness, and sends the request to the server. When the server responds, an HTML table is built, the nodes (elements) are extracted from the XML file, and the copy placeholder is updated with an HTML table populated with XML data.
The servlet calls the SQL statement Select to isolate the data and convert the output into XML format.
AJAX XML Instance (http://www.w3school.com.cn/ajax/ajax_xmlfile.asp).
The output XML file code can be referenced (http://wentao365.iteye.com/blog/1102815).
3.2. Output JSON:
When the user clicks on the "Get JSON" button above, the Loadxmldoc () function is executed. The Loadxmldoc () function creates a XMLHttpRequest object, adds a function that executes when the server responds in readiness, and sends the request to the server. When the server responds, an HTML table is built, the nodes (elements) are extracted from the JSON file, and the copy placeholder is updated with an HTML table filled with JSON data.
The servlet invokes the SQL statement select to isolate the data and convert the output to JSON format. The Jsonstringer class is used when converting to JSON format
Ajax gets the servlet to get the output JSON file for reference (http://bbs.csdn.net/topics/390708035) on the 8 floor.
The output JSON file code can be referenced (HTTP://WWW.TUICOOL.COM/ARTICLES/6NIEJY).

A little summary of the press release

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.