4. Naming rules
4.1 Project No. Naming rules
To be improved
4.2 document naming rules
To be improved
4.3 JSP/html naming rules
JSP and HTML file names are all in lower case and follow the following specifications:
Data/content display page
Multiple words are separated by underscores (_ list), which indicates the information of the displayed content. To avoid conflicts, add "_ list ". For example:
New_message.html or my_file_list.jsp
Operation page
Naming format: Noun _ underline _ verb, for example, file_delete.jsp.
Page with Frame
In <frameset>, the name attribute of <frame> is named in the format of ① XXX. _ ② XXX _ ③ XXX.
① The xxx part is used to identify which function module of the current page belongs to the entire system.
For example, if it belongs to ebwebmail, it is represented as ebwebmail, and in other cases, and so on.
② The xxx part identifies the functions to be completed on the current page.
For example, the login function is used to complete user logon, and other cases are used in turn.
③ The xxx part is used to indicate the position of the page in the browser window.
At the top of the browser window, it is marked as top, and in other cases, and so on.
Example: ebwebmail_inbox_top.jsp
<Frame> we recommend that you underline the name of the file corresponding to the src attribute in the original naming convention and add the location of the window.
Javascript script method
All script functions are named in the form of ① XXX _ ② XXX.
① Modules of the page corresponding to XXX.
② XXX indicates the function to be implemented by the function (dynamic object structure). Multiple words are connected by underscores.
Example: ebwebmail_send_mail ()
Common module script functions must be collected in a JS file and imported on the page in the form of <script language = "JavaScript" src = "url"> </SCRIPT>. JS file names use the module name, for example, ebwebmail. js.
If the project already provides a public JS script, use the functions provided in the public JS script first.
The <SCRIPT> element of all methods is defined in
Internal variables and parameters of JavaScript scripts
Words are separated by underscores (_) and all lowercase letters, for example, VAR file_size.
<Form> form name attribute
It must start with "form _" and then add the information to be collected by the form, for example, form_file_upload or form_send_mail.
Form Elements
The name of the form element is named based on the information to be collected by the element. Words are separated by underscores (_) and all lowercase letters are used. For example:
<Input type = "text" name = "username">
<Input type = "radio" name = "file_type">
<Textarea name = "content" rows = "5" Cols = "40"> |
Cookie name
Naming format: module name_storage information noun (multiple words are separated by underscores), all uppercase, for example, ebwebmail_sort_type.
Name of the name parameter in window. Open
The window. Open Method in Javascript has a name parameter. The browser stipulates that only one window with the same name can be opened. If the names of different programs are repeated, they will conflict with each other. If you do not limit the number of opened windows, you can specify ''or" "(not null). Otherwise, you must add the module name, such as ebwebmail_viewmail.
4.4 database naming rules
Database Table naming rules are as follows:
Module name_storage information nouns (multiple words are separated by underscores), all in lower case, for example, ebwebmail_message.
The database Field naming rules are as follows:
Storage information nouns (separated by underscores), all in lower case, for example, message_id.
5 Documentation specifications
1. Currently, the main tools used for document writing are word (except for project planning documents, which must be made using projects). The auxiliary tools include Visio, PowerPoint, and Erwin.
2. documents must be in the same format, text font, color, and size.
3. if you want to extract the content on the HTML page, you cannot directly paste it from the HTML page (HTML format will be left in the Word document), but you must first remove the format, for example, paste it to notepad first.
4. Pay attention to Chinese and English Punctuation Marks. Chinese Punctuation Marks are used in the document body.
5. Do not use the drawing tool that comes with word if you need illustrations in the document. You can choose to use PowerPoint or Visio. Use PowerPoint and select "insert"> "object"> "Microsoft PowerPoint slides ". When Using Visio, you need to create another Visio Document and paste it into word after drawing.
6. Data Modeling uses the Erwin tool. In this document, you only need to paste the logical view of the data model, and add the table structure description.
7. The revision mode must be used to modify others' documents so that the modified content can be retained. In the revision mode, select "Tools"> "revision"> "highlight revisions" to mark revisions during editing ".
Appendix: templates
Ü Java class documentation)
Statement:
Description:
Attribute: 1. property_name
Statement
Description
Method: 1. method_name
Statement
Description
Parameters
Return Value
Exception
Note:
In the method declaration, if you encounter an overloaded method, you can use "|" to accept different types of parameters, such as "string value | int value "; you can use "[]" to indicate optional parameters, for example, "Object message [, throwable T]".
Servlet document)
Description of the List of accepted parameters for the class name
Data Modeling)
Table Name: some_table
Description:
Table Structure:
Field name type description
6. Code Specification
6.1 Java source code specification
6.1.1 name
U package name
The package name must be a lowercase word, for example, net. ebseries. modules.
In addition, we make the following conventions for the package name:
1. the prefix of the toolfunction package name is. util.
2. the prefix of the servlet class package name is. servlet.
3. the prefix of the test case package name is. Test.
Class Name
The class name must start with an upper-case letter, and all other letters must be lowercase words, such as datafile or infoparser.
Class variable name
The variable name must start with a lowercase letter. The following words start with an uppercase letter, such as debug or inputfilesize.
Static final variable name
The names of static final variables should be in uppercase and indicate the complete meaning, for example, max_upload_file_size = 1024.
Parameter Name
The parameter name must be consistent with the variable naming rules.
Array name
Arrays should always be named in the following way:
Byte [] buffer;
Instead:
Byte buffer [];
Method Parameters
Use meaningful parameter names. If possible, use the same name as the field to be assigned values:
Setcounter (INT size)
{
This. size = size;
} |
6.1.2 Code Format
File Header Declaration
The source file header requires a history segment, which must be specified in the History segment for each major change to the source file. This section is defined between package and import. For example:
/*************************************** **************
* History
*
* 2002/01/29 biz File Creation
*
* Kevin added new features
*
**************************************** ***************/ |
Import Order
Import packages in the following order:
1. JDK standard package
2. Java extension packages (such as servlet, javamail, and JCE)
3. packages of the External library used (for example, XML Parser)
4. Public packages of the project used
5. Other packages of the modules used
A line feed is added to each type of import.
|
For example:
Import java. Io .*;
Import java. util .*;
Import javax. servlet .*;
Import javax. Mail .*;
Import org. Apache. xml .*;
Import net. ebseries .*;
Import net. ebseries. util .*;
Import net. ebseries. ebwebmail .*; |
Code block writing format
You can choose to write any of the following code blocks:
|
If (true ){
// Body
}
If (true)
{
// Body
} |
The second writing method is recommended. To modify others' code, you must use the original code writing method.
For a code block that is too long and has more than 1 screen,} The code block must be described later. For example:
If (I> 100)
{
// Too multiple lines more than one screen
} // If (I & gt; 100) |
Indentation
Indentation uses four consecutive spaces. Do not save the tab characters in the source file. Be sure to adjust the IDE tool used to enable the function of converting tab to space.
Page width
The page width should be set to 80 characters. the source code generally does not exceed this width, and thus cannot be fully displayed. However, this setting can be flexibly adjusted. in any case, extra-long statements should be folded after a comma or an operator. after a statement is folded, four spaces are indented before the original statement.
Operator
Each operator is separated by a space.
For example:
Int A = B;
If (a> 0 );
SQL statement
The SQL statement written in the Code requires that all SQL keywords should be in upper case, and the table name and field name should be in lower case. For example:
Select user_id, name from account where user_id>? And depart =? Order by name
Class and method definition
The class definition or method definition is too long and must be written in line breaks. For example:
|
Public class counterset
Extends observable
Implements cloneable
Private portletset getportlets (portlets,
Rundata,
Boolean application,
Boolean applicationsonly)
{
} |
6.1.3 notes
Javadoc comments must be written for public and protected member variables and methods. More than one sentence of comments is written in Chinese. Javadoc comments must be written for private methods with more than 10 lines of code.
You need to write comments for the logical branches or loop conditions in the code, for example:
If (some condition)
{
// Meets a certain condition and should be handled in this way
}
Else
{
// Otherwise it should be handled in that way
} |
6.1.4 others
About attributes
The attributes in the class cannot be defined as public variables for direct access. Instead, they are defined as protect variables and the get/set method is compiled. For example:
|
Protect string myname;
Public String getmyname ()
{
Return myname;
}
Public void setmyname (string myname)
{
This. myname = myname;
} |
6.2 JSP/html code specifications
JSP/html description comment
A basic description comment must exist at the top of the JSP/html page, including the function description, parameter list, and historical modification information. For example:
<% --
/*************************************** ***********
*
* Name: file_download.jsp
*
* Purpose: File Download prompt
*
* Parameters:
* File_id-File ID
* Force? C force download?
*
* History
*
* 2002/04/05 hafele create a file
*
* /06/07 TMP added the force-Down Function
*
**************************************** *********/
-- %> |
JSP Header Format
JSP headers generally follow the following format:
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. Io. *" %> // JDK standard package
<% @ Page import = "javax. Mail. *" %> // Java extension package
<% @ Page import = "org. Apache. xml. *" %> // packages of the External library used
<% @ Page import = "com. Sunrise .. *" %> // public package of the project in use
<% @ Page import = "com. Sunrise. Applications. *" %> // other packages of the modules used
<% @ Include file = "Some. jsp" %> // include other JSP
<%
Response. setheader ("Pragma", "No-Cache ");
Response. setheader ("cache-control", "No-Cache ");
Response. setheader ("expires", "0 ");
%> // Generally, JSP files must be cached. |
HTML Format
1. html headers generally follow the following format:
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> some title </title>
<LINK rel = "stylesheet" href = "some.css" type = "text/CSS">
<Script language = "JavaScript">
// Some Javascript
</SCRIPT>
</Head> |
Note: You must specify a meaningful <title>. You are not allowed to see <title> such as "Untitled" or "Untitled.
2. All HTML tags are in lower case.
3. A background color (generally # ffffff) needs to be set for an HTML page ).
HTML syntax Validation
All JSP/html pages must be properly opened using Dreamweaver (that is, the HTML syntax is correct and there is no error mark ).
Note
Generally, HTML comments are not used unless it is necessary for end users to see the content. JSP comments must be used for HTML blocks containing JSP code. You must remove unnecessary comments from the release version.
Maxlength of the form field
For text-type input fields, you must set the corresponding maxlength according to the length of the database field. For example, if the database type is varchar (64 ), so maxlength is 32 (because the Chinese browser also considers Chinese as a character ).
6.3 Other Specifications
IDE usage
Currently, there is no restriction on the use of development tools, but the final submitted code must be independent of any IDE, and ant can be used to complete all compilation work. Generally, the format of the submitted code directory is as follows:
| _ Dist (stores the output file class file)
| _ Lib (used library)
| _ SRC (source code)
| _ Docs (document)
| _ Wwwroot (page file)
| _ Build. XML (ANT Build File)
| _ Changes. Log (code version and modified log) |
Restrict the use of sessions
When using sessions in the code, you need to listen to the opinions of the Project Manager. The project manager needs to register the names and functions of all sessions used in the project in the design document.
Restrict the use of external packages
If an external package needs to be used, the developer should listen to the opinions of the Project Manager. Prior to approval by the project manager, it is strictly prohibited to use an external package without authorization.