Background technology
Along with the commercialization of Internet, its technology has also obtained fast development.Html page cooperates with browser to be become users with its friendly interface and visits main, the common mode of Internet, this mode is general, general owing to client, thereby also begins gradually to be applied in the management of embedded system (as switch, router); And, customize to different users in order to make information faces, need in embedded system, provide a kind of and can independently realize the dynamically technology of output of html page.
In the prior art, be used to realize that the method that html page is dynamically exported mainly comprises: CGI (Common gateway interface) (CGI, Common Gateway Interface); And various scripts, as the technology based on server end such as dynamic state server homepage (ASP, Active Server Page), java server homepage (JSP, Java Server Page), PHP.
In the CGI technology, can adopt different programming languages to write the program that meets the CGI standard, this program is moved on server, and with operation result by Server Transport to the browser of client.Set up getting in touch between the WEB page and the background program by the CGI standard, and utilize the information of routine processes visitor input also to respond in view of the above, be specially: server is dynamic content according to the HTTP request address that browser sends as if the discovery requested resource, then call corresponding processing program, program is collected output information and is generated back page (HTML, script code, literal etc.), send to client by server at last and reply the page, the back page that generates is once outputed to client.
The defective of CGI technology is: the output of adopting the CGI technology to carry out the HTML dynamic page need rely on the Premium Features of operating systems such as environmental variance and pipeline, and embedded device is subject to CPU and memory size, can't realize; And because each dynamically html page of output of revising then needs to revise cgi script, and then if described program is a binary program, then also must again this program compilation be become executable file, the form of presentation that has caused CGI is difficulty and inefficiency relatively; And, because dynamic content and the static content that will export fixedly write code, cause page layout design personnel and program development personnel conveniently to safeguard to the code of being responsible for separately, reduced work efficiency.
With PHP is the method for dynamically exporting html page in the example explanation prior art by script.
PHP is a kind of script that embeds html file, better realizes page control thereby can directly add scripted code in html source file.For example: PHP regulation, with "<? php " the sign beginning, finish the middle content that will carry out for the PHP script, the conditional control statement that defines comprising PHP, loop statement etc. with "?〉" sign.The PHP script operates in the WEB service end, according to the data generation dynamic web page of user's request and server end, and has very strong database access ability.
In PHP, the processing of dynamic content is mainly finished by script, the system environments when script can obtain script executing by the function of script interpreter definition.Concrete, when the request of a PHP file of server response, script interpreter can directly be delivered on the browser for the HTML coding of standard in the file, embedded PHP code is then explained by script interpreter earlier and is carried out, if output is arranged, then output information is sent to browser as the part of HTML.
The defective of described PHP technology is: because script interpreter is powerful, own perfect grammer system is arranged, support that characteristic is many, thereby implement more complicated, and embedded device is subject to CPU and memory size, the difficult script interpreter function that realizes complexity; And, still embed the code of more control script executing in the static html file, be unfavorable for page layout design personnel and program development personnel maintenance to the page.
In sum, prior art is subjected to the restriction of embedded system CPU and memory size, the difficult dynamic output that realizes the embedded system html page; And prior art has increased maintenance difficulties, has limited the raising of work efficiency.
Summary of the invention
The problem to be solved in the present invention provides the dynamically method of output of a kind of HTTP webpage, and this method can reduce the demand of web page dynamic contents output to system resource.And the present invention also provides the dynamically system of output of a kind of HTTP of being used for webpage accordingly.
For solving the problems of the technologies described above, the objective of the invention is to be achieved through the following technical solutions:
A kind of HTTP webpage is the method for output dynamically, comprising: 1) preset html file, comprise predefined function control mark corresponding to dynamic content; Preparatory function control program, and dynamic replacement steering logic are used for the semantic processes to described mark, the calling function steering logic; 2) the dynamic replacement steering logic is read in html file; For the function control mark in the file, dynamic replacement steering logic calling function control program carries out computing or dynamic content output; 3) static content in the dynamic replacement steering logic output html file.
Described function control mark is that dynamic value is replaced mark or dynamic iteration is replaced mark or dynamic condition is replaced mark or dynamically comprised the replacement mark.Described function control mark adopts HTML grammatical markers mode, and is different from the grammatical markers that HTML has stipulated.
On the said method basis, 3) comprise further in that the dynamic replacement steering logic carries out the output of static content in the html file according to function control program operation result.
1) html file is corresponding to a function control program in.
A kind of dynamically system of output of HTTP webpage that is used for, comprising: html file comprises the function control mark or the standard html text that preset in the described file; The dynamic replacement control module reads html file, outputting standard html text content; For the function control mark, the dynamic replacement unit carries out function corresponding according to described marking of control function control unit to be handled; Function control unit is used to carry out the output of function computing or dynamic content.
On the said system architecture basics, the dynamic replacement control module further obtains the execution result of function control unit, and carries out the output of standard html text content according to this result.
The executable function treatment of described function control unit is that dynamic value is replaced or dynamic iteration is replaced or dynamic condition is replaced or dynamically comprises replacement.And described function control mark adopts HTML grammatical markers mode, and is different from the grammatical markers that HTML has stipulated.
Above technical scheme as can be seen, the present invention has adopted the thought of replacing in html file, calculation function when being from html file, to remove dynamic content output, the calculation function that is about to be used for dynamic content output is peeled off from html file, carry out computing by specific function control program, and be responsible for the dynamic content that computing obtains is exported; By the operation of dynamic replacement steering logic control whole functional, and common html file content exported in proper order.
From the above, the html page element separates fully with the function steering logic, described function control program is only realized the replacement of dynamic content, the dynamic content that is substituted in the html file is exported in html file order output procedure, compared with prior art, because the method that dynamic content has adopted variable to replace, thereby the output of dynamic content will not influence the design of the webpage static content and the whole space of a whole page.And then based on the advantage of above-mentioned technology, the present invention can improve the development efficiency of webpage, reduces maintenance cost.
From the above, compare with existing CGI technology, realization of the present invention does not rely on operating system advanced features such as environmental variance and pipeline, and simultaneously because embedded system does not have described advanced feature, thereby the present invention compares the output that CGI is fit to realize page dynamic content in the embedded system more.
Compare with the technology of existing script interpreter, the defined dynamic replacement steering logic of the present invention is simpler, only be used for the control of processing logic, and the processing of not responsible dynamic content, the processing of web page dynamic contents and output are responsible for by the function steering logic of pending page correspondence; Therefore, of the present invention based on the HTML rule, the method that specific function control is embedded html file need not take too much CPU and memory source, thereby is suitable for realizing in embedded system the output of html web page dynamic content more.
In sum, the present invention can improve maintenance of netpage efficient; And the present invention realizes on embedded device, has lightweight, to take resource few, and function is simple, reliable, flexible characteristic.
Embodiment
The invention provides the dynamically method of output of a kind of HTTP webpage, its core is to comprise: dynamic replacement steering logic, the html template page, function control program; The dynamic replacement steering logic is fixed, and the function steering logic and the html page are supporting; The standard part of the Html page is by the output of dynamic replacement steering logic, and dynamic content is exported by the function steering logic.Preset html file, comprise predefined function control mark corresponding to dynamic content; Preparatory function control program, and dynamic replacement steering logic are used for the semantic processes to described mark, the calling function steering logic; The dynamic replacement steering logic is read in html file; For the function control mark in the file, dynamic replacement steering logic calling function control program carries out computing or dynamic content output; Static content in the dynamic replacement steering logic output html file.
Fig. 1 is the dynamic output intent process flow diagram of HTTP webpage of the present invention.With reference to Fig. 1, the implementation of this method is described.
Step 11: preset the dynamic replacement steering logic.Be used to realize reading in of html template file the output of static content in the html file, the semantic processes of self-defined html tag, the calling of function steering logic.
According to service needed, preset the WEB webpage and dynamically export required allocation function control program, be used to finish the replacement and the computing of dynamic content; Wherein, the dynamic content of described webpage is meant the specifying information that depends on execution environment, the variation that these information are not stopped in the process of system's operation; Static content is meant the content that remains unchanged in system's operational process.Static content solidifies in the html template file, and dynamic content is dynamically exported according to actual conditions by the function control program.
Preset html file according to business demand, determine page output form, in described html file, generally include the received text of HTML, be used to realize the output of webpage static content; And according to the needs of business, having some dynamic contents in the webpage needs output, thereby in the present invention, also comprises in the described html file and be used to call described function functions of control program control mark; Describedly define when being marked at the preparatory function control program,, carry out specific function treatment operation to realize the calling function control program corresponding to function steering logic specific in the function control program.
In described html file, described function control mark adopts the standard mark mode of HTML, and outside the standard label range of html grammatical norm, for example: the mark of above-mentioned value replacement operation may be defined as<*, because in the grammer of HTML,<the punctuation mark of following later can show in browser; And hereinafter as seen, according to concrete business demand, tag definitions with dynamic iteration replacement operation in the specific embodiment hereinafter is<Iterate nNameList 〉, wherein Iterate is the routine call key word, nNameList is an identifier, the tag definitions of dynamic condition replacement operation is<IfiIsStudent 〉, in like manner If is the routine call key word, iIsStudent is an identifier, or dynamically comprise replacement operation<Includesrc=" footer.html " 〉, wherein Include is a key word, and src represents employed file, and footer.html is the concrete a certain html file among this embodiment.Because those dynamic replacement mark browsers can not be discerned and can not be revealed, therefore, the html template page of dynamic replacement has stronger readability equally.
Usually, the corresponding supporting function control program of each html file, among the present invention, also can handling procedure of a plurality of html file sharings, but can make the function control program relative complex that becomes.
Step 12:, start the output of content of pages according to the request of client browser.
Step 13: read in the described html file that presets according to business demand.
Step 14: follow the HTML rule content of pages of html file is exported in proper order, in output procedure, judge that the current html file content that is about to export is predefined function control mark, or the html text of standard; If described function control mark then carry out step 16, if the html text of standard or standard mark then carry out steps 15.
Step 15: directly described standard html text or standard mark are exported, common described standard html text or standard mark are presented as the part of the static content of the page, in the present invention promptly, for the content of static state, directly export by the dynamic replacement steering logic.
Step 16: the calling function control program carries out function treatment; In the html file output procedure, if run into predefined function control mark, then the calling function control program for example can directly be realized calling by the function of c language; And the type of functionality steering logic according to this mark is carried out function treatment, for example replaces mark<* if run into above the value of definition 〉, this function control program value replacement operation then; And carry out step 17.
Step 17: the result that the computing of function control program is carried out turns back to the dynamic replacement steering logic; Be after routine call finishes, the function control program turns back to the dynamic replacement steering logic with the output of page dynamic content or with operation result, the dynamic replacement steering logic obtains the operation result of function control program, if the customize tag in the html file is replaced mark for value, then the dynamic replacement steering logic continues to handle the remainder of html file, if what run in the html file is logical operation mark (replacing mark as condition), then the dynamic replacement steering logic is carried out logical process according to the rreturn value of function steering logic, can skip one section html page (respective conditions replacement mark), or repeat one section html page (corresponding iteration replacement mark).
Step 18: end of output.In the html file that presets, may include many places function control mark, then turn back to step 14, the step of html file output is carried out in circulation.
Below, in conjunction with above,, embody implementation method of the present invention by a specific embodiment.
<html>
<head>
<title>
hello?page
</title>
<body>
This?is?a?dynamic?output:<*vValueOutput>.
<P>
This?is?an?iterate?output:
<table>
<tr><th>No.<th>Name</tr>
<IteratenNameList>
<tr><td><*nNumber><td><*aName></tr>
</Iterate>
</table>
<P>
This?is?a?condition?test
<IfiIsStudent>
He?is?a?student
<Else>
He?is?not?a?student
</If>
<P>
This?is?a?include?test:
<Include?src=″footer.html″>
</Include>
</body>
</html>
It more than is a html Page Template.When the beginning web page contents, at first read in html Page Template file, analyze and handle html Page Template file.When running into predefined page control element, then the calling function steering logic is done function and is handled; For non-predefined control element,, then directly export by the dynamic replacement steering logic as html standard mark and plain text.Wherein, described function steering logic is to define according to business demand.
In above-mentioned template file, comprised 4 predefined function control marks, wherein:
<
*VValueOutput〉be the value replacement mark of dynamic replacement in the present embodiment.In the html file output procedure, if run into this value replacement mark, then with vValueOutput as parameter, the calling function control program is responsible for the computing of particular content by function steering logic wherein, the dynamic content that the function control program will be exported is directly exported.
<Iterate nNameList〉be the iteration replacement mark of dynamic replacement in the present embodiment.In the html file output procedure, if run into this mark, then with nNameList as parameter, the calling function control program, function steering logic is not wherein exported any particular content this moment, just carries out the operation of initialization internal environment.When run into<
*NNumber〉or<
*AName〉time, this mark value of belonging to dynamic replacement is replaced mark as can be known, then exports particular content respectively according to the method for above-mentioned functions control operation, continues to analyze this html file template, when run into</Iterate the time, showing that iteration is replaced finishes.At this moment, resend<Iterate nNameList to the function control program, carry out iterative process again one time by the control of function control program, perhaps, finish this iteration replacement operation and then continue to handle the residue content.Zero degree might take place in the process that described iteration is replaced, and just directly withdraws from when promptly entering for the first time, does not export any content; Might take place once, carry out computing when promptly entering for the first time, carry out necessary value and replace, directly withdraw from when entering for the second time; Might take place repeatedly, promptly replacement process has taken place many times.The number of times of replacing generation is specifically controlled by the function control program according to business demand.
<If iIsStudent〉be the condition replacement mark of dynamic replacement in the present embodiment.In the html file output procedure, if run into this mark, then with iIsStudent as parameter, the calling function control program be true or is vacation by its function steering logic Rule of judgment.If the logical value that the function control program returns is for true, then according to top html file for example, will export<If iIsStudent〉after content, up to running into<Else〉or</If till; The logical value that the function control program returns then directly finds<Else for false 〉, and processing<Else the content of back, up to run into</If; If do not find<Else〉just run into</If 〉, then can not export any content, and continue handle</If〉all the other contents of back.
<Include src=" footer.html "〉for dynamic replacement in the present embodiment comprise the replacement mark, in the html file output procedure,, then directly read the footer.html file, and output by the dynamic replacement steering logic if run into this mark.Described footer.html file is another pagefile that need export in the present embodiment, under the calling of dynamic replacement steering logic, directly reads in this footer.html file and output in the process of the above-mentioned html file content of output.Because this process and concrete independent of service, all be to read and export a file, this processing procedure does not have the participation of function steering logic, be subject to the resource such as internal memory, task stack of embedded system in the processing procedure of file f ooter.html, do not check yet and whether comprise effective dynamic replacement mark, but, behind the file end of output, continue to handle all the other contents directly as static html page output.
After whole file was finished dealing with according to the method described above, the function of dynamic replacement was also promptly finished.
Below be the output example of above-mentioned html file, iteration replacement number of times is zero in this example, and condition is controlled to be very.
<html>
<head>
<title>
hello?page
</title>
</head>
<body>
This?is?a?dynamic?output:value?output.
<P>
This?is?an?iterate?output:
<table>
<tr><th>No.<th>Name</tr>
</table>
<P>
This?is?a?condition?test
He?is?a?student
<P>
This?is?a?include?test:
<div?id=”bottom”><hr></div>
</body>
</html>
Below replacing number of times for iteration is 3, and condition is controlled to be false output example.
<html>
<head>
<title>
hello?page
</title>
</head>
<body>
This?is?a?dynamic?output:dynamic?test.
<P>
This?is?an?iterate?output:
<table>
<tr><th>No.<th>Name</tr>
<tr><td>1<td>Zhang?San</tr>
<tr><td>2<td>Li?Si</tr>
<tr><td>3<td>Wang?Wu</tr>
</table>
<P>
This?is?a?condition?test
He?is?not?a?student
<P>
This?is?a?include?test:
<div?id=”bottom”>Copyright?by?Huawei-3com?Co.,Ltd</div>
</body>
</html>
Based on the above method, the operation of the dynamic replacement among the present invention can be carried out nested, promptly shows as the dynamic replacement mark and supports nested.As:
<Ifa>
See?the?flowing:
<Iterate?b>
value?is?need:<*vValue>
</Iterate?b>
You?can?choose:
<Ifc>
<Else>
That‘s?imposible.
</If>
</If>
As indicated above, function control mark among the present invention adopts the mark mode identical with the HTML grammer, and outside the standard label range of html grammatical norm, and then this function control mark can be not viewed device show that and this mark mode makes the html template page have higher readability.The display effect of the html template page in IE in the last example as shown in Figure 2.
On said method and embodiment basis, the present invention does not limit the implementation of described function control program, and the technician can realize the computing of dynamic content in the specific webpage according to business demand with mode not of the same race.For example, can obtain status information, also can obtain corresponding information by the access file system by access system resources.
The present invention also provides the dynamically system of output of a kind of HTTP of being used for webpage, comprises html file, comprises the function control mark or the standard html text that preset in the described file; The dynamic replacement control module reads html file from described page location, for the standard html text, directly export; For the function control mark, the dynamic replacement unit carries out function corresponding according to described marking of control function control unit to be handled; And, obtain the execution result of function control unit, and be substituted in the html file, carry out html file output according to described execution result; Function control unit is used to carry out function treatment, and execution result is turned back to the dynamic replacement unit.
With reference to Fig. 3, specify the present invention and be used for the dynamically system of output of HTTP webpage.
Html file comprises the function control mark and the standard html text that preset.
Preset html file according to business demand, in described html file, generally include the received text of HTML, be used to realize the output of webpage static content; And according to the needs of business, having some dynamic contents in the webpage needs output, thereby in the present invention, also comprises in the described html file and be used to call described function functions of control program control mark; Describedly define when being marked at the preparatory function control program,, carry out specific function treatment operation to realize the calling function control program corresponding to function steering logic specific in the function control program.
In the html file that generates, described function control mark adopts the standard mark mode of HTML, and outside the standard label range of html grammatical norm, the concrete grammar reference is giving an example of method above.
The dynamic replacement control module reads the html template file, and analyzes, and for HTML standard mark and plain text, directly exports; For predefined page function control mark, then the function steering logic of calling function control module is carried out calculation process; And for the operation result that function control unit is returned, the dynamic replacement control module continues to handle remaining html template file.
In the function control unit, comprise the function steering logic that presets according to business demand, be used to carry out function control operation computing.
With illustrated embodiment in the method above is example, and in html file content output procedure, the working method of dynamic replacement control module and function control unit is as follows.
When run into<
*VValueOutput〉time, find that this is that the value of a dynamic replacement is replaced mark, then with vValueOutput as parameter, the calling function steering logic is responsible for the output of concrete dynamic content by the function steering logic.Behind the end of output, control turns back to the dynamic replacement control module, continues to handle all the other contents.
When running into<Iterate nNameList〉time, find that this is that the iteration of a dynamic replacement is replaced mark, then with nNameList as parameter, the calling function steering logic, the function steering logic can not be exported any particular content this moment, just the internal environment of initialization oneself.After the end, control turns back to the dynamic replacement control module, continues to handle all the other contents.When run into<
*NNumber〉or<
*AName〉time, particular content exported respectively by the function steering logic.The dynamic replacement control module continues operation, when run into</Iterate the time, know that iteration is replaced to be through with.At this moment, the dynamic replacement control module can resend<IteratenNameList〉to the function steering logic, be to carry out iterative process again one time by the control of function steering logic, or finishing iteration is replaced continuation processing residue content.Zero degree might take place in the process that iteration is replaced, and just directly withdraws from when promptly entering for the first time, does not export any content; Might take place once, continue operation when promptly entering for the first time, carry out necessary value and replace, notice dynamic replacement logic withdraws from when entering for the second time; Also might take place repeatedly, promptly replacement process has taken place many times.Replacing the number of times that takes place is controlled fully by the function steering logic.
When running into<If iIsStudent〉time, find that this is that the condition of a dynamic replacement is replaced mark, then with iIsStudent as parameter, the calling function steering logic determines that by the computing of function steering logic condition is true or for false.If condition is true, then the dynamic replacement control module can be handled<If iIsStudent〉content of back, up to running into<Else〉or</If 〉.If condition is false, then directly find<Else 〉, and processing<Else the content of back, up to run into</If; If do not find<Else〉just run into</If 〉, then can not export any content, directly continue to handle</If〉all the other contents of back.
When running into<Include src=" footer.html "〉time, find this be a dynamic replacement comprise the replacement mark, then directly read in the footer.html file, and output by the dynamic replacement control module.Because this process and concrete independent of service, all be to read and export a file, this processing procedure does not have the participation of function steering logic, be subject to the resource such as internal memory, task stack of embedded system in the processing procedure of file f ooter.html, can not check whether effective dynamic replacement mark is arranged yet, but directly as static html page output.Behind the file end of output, continue to handle all the other contents.
After whole file processing was finished, the function of dynamic replacement was promptly finished.
More than to HTTP webpage provided by the present invention dynamically the method and system of output be described in detail, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that all can change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.