锘??xml version="1.0" encoding="utf-8" standalone="yes"?>97久久精品亚洲中文字幕无码,亚洲国产精品日韩,亚洲精品国产第1页http://www.tkk7.com/zhuyan/category/21312.htmlJAVA鍚彂鑰?/description>zh-cnFri, 06 Apr 2007 00:30:00 GMTFri, 06 Apr 2007 00:30:00 GMT60VTL鎸囧崡http://www.tkk7.com/zhuyan/articles/108820.html鏈卞博鏈卞博Thu, 05 Apr 2007 15:50:00 GMThttp://www.tkk7.com/zhuyan/articles/108820.htmlhttp://www.tkk7.com/zhuyan/comments/108820.htmlhttp://www.tkk7.com/zhuyan/articles/108820.html#Feedback0http://www.tkk7.com/zhuyan/comments/commentRss/108820.htmlhttp://www.tkk7.com/zhuyan/services/trackbacks/108820.html鍏充簬璇ユ寚鍗桝bout this Guide

榪欐槸鍏充簬Velocity妯$増璇█鐨勬寚鍗椼傝寰楀埌鏇村鐨勪俊鎭紝璇峰弬闃匳elocity 鐢ㄦ埛鎵嬪唽銆俆his guide is the reference for the Velocity Template Language (VTL). For more information, please also refer to the Velocity User Guide.

鍙傝僐eferences

鍙橀噺Variables

鍚堟硶鐨勫彉閲忚鍒欙細Notation:

$ [ ! ][ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ][ } ]

渚嬪瓙錛欵xamples:

  • Normal notation錛堟櫘閫氱殑鍐欐硶錛屽鏋渕ud-Slinger_9 涓嶅瓨鍦紝鍒欎細鏄劇ずmud-Slinger_9 錛? $mud-Slinger_9
  • Silent notation錛堝鏋渕ud-Slinger_9 涓嶅瓨鍦紝鍒欎笉鏄劇ず浠諱綍涓滆タ錛? $!mud-Slinger_9
  • Formal notation錛堟瑙勭殑鍐欐硶錛岃兘鏈姝g‘鐨勫尯鍒彉閲忓悕瀛楋級: ${mud-Slinger_9}

    灞炴roperties

鍚堟硶鐨勮鍒欙細Notation:

$ [ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, ]* .[a..z, A..Z ][ a..z, A-Z, 0..9, -, ]* [ } ]

渚嬪瓙 Examples:

  • Regular Notation: $customer.Address
  • Formal Notation: ${purchase.Total}

    鏂規硶Methods

鍚堟硶鐨勮鍒橬otation:

$ [ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, ]* .[ a..z, A..Z ][ a..z, A..Z, 0..9, -, ]*( [ opional parameter list... ] ) [ } ]

渚嬪瓙錛欵xamples:

  • Regular Notation: $customer.getAddress()
  • Formal Notation: ${purchase.getTotal()}
  • Regular Notation with Parameter List錛堝甫鏈夊弬鏁扮殑鏂規硶鐨勬瑙勮皟鐢ㄦ柟寮忥級: $page.setTitle( "My Home Page" )
    VTL灞炴ц皟鐢紙get鍜宻et鏂規硶錛夊彲浠ヨ綆鍐欍傛瘮濡俖$object.getMethod()鍜?object.setMethod()_ 鏂規硶閮藉彲浠ョ畝鍐欐垚_$object.Method_銆傚湪浣跨敤鐨勬椂鍊欙紝鎴戜滑鏇村亸濂戒嬌鐢ㄥ悗鑰?鍗崇畝鍖栫殑鍐欐硶銆備嬌鐢ㄨ皟鐢ㄦ柟娉曡繖縐嶅啓娉曠殑鏈澶х殑濂藉灝卞湪浜庝綘鑳藉悜鍏朵腑浼犻掍竴浜涘弬鏁般俈TL Properties can be used as a shorthand notation for VTL Methods that take get and set. Either $object.getMethod() or $object.setMethod() can be abbreviated as $object.Method. It is generally preferable to use a Property when available. The main difference between Properties and Methods is that you can specify a parameter list to a Method.

    璇彞Directives

#set - 緇欎竴涓紩鐢ㄨ祴鍊糆stablishes the value of a reference

鏍煎紡錛欶ormat:

#set( $*ref *= [ ", ' ]arg[ ", ' ] )

鍏朵腑錛歎sage:

  • $ref - 宸︽搷浣滄暟搴旇鏄竴涓彉閲忕殑寮曠敤鎴栬呬竴涓睘鎬х殑寮曠敤銆俆he LHS of the assignment must be a variable reference or a property reference.
  • arg - 鍙蟲搷浣滐紝濡傛灉鍙蟲搷浣滄暟鏄鍙屽紩鍙鋒嫭璧鋒潵鐨勮瘽錛岄偅涔堝湪璧嬪肩粰宸︽搷浣滄暟鐨勬椂鍊欙紝榪斿洖鐨勬槸鍙蟲搷浣滄暟瑙f瀽鍑烘潵鐨勫鹼紝濡傛灉鍙蟲搷浣滄暟鏄鍗曞紩鍙鋒嫭璧鋒潵鐨勮瘽錛岄偅涔堝氨鐩存帴璧嬪肩粰宸︽搷浣滄暟銆傚鏋滃彸鎿嶄綔鏁扮殑瑙f瀽鐨勭粨鏋滀負null鐨勮瘽錛屼笉浼氱粰宸︽搷浣滄暟璧嬪箋俆he RHS of the assignment, arg is parsed if enclosed in double quotes, and not parsed if enclosed in single quotes. If the RHS evaluates to null , it is not assigned to the LHS.

渚嬪瓙錛欵xamples:

  • 鍙橀噺鐨勫紩鐢細Variable reference: #set( $monkey = "bill" )
  • 緇欏睘鎬ц祴鍊鹼細String literal: #set( $monkey.Friend = "monica" )
  • 灞炴ц祴鍊鹼細Property reference: #set( $monkey.Blame = $whitehouse.Leak )
  • 鏂規硶寮曠敤錛歁ethod reference: #set( $monkey.Plan = $spindoctor.weave($web) )
  • Number literal: #set( $monkey.Number = 123 )
  • Range operator: #set( $monkey.Numbers = [1..3] )
  • Object array: #set( $monkey.Say = ["Not", $my, "fault"] )

鍙蟲搷浣滄暟涔熷彲浠ユ槸綆鍗曠殑鏁板琛ㄨ揪寮忥紝姣斿錛歍he RHS can also be a simple arithmetic expression, such as:

  • Addition: #set( $value = $foo + 1 )
  • Subtraction: #set( $value = $bar - 1 )
  • Multiplication: #set( $value = $foo * $bar )
  • Division: #set( $value = $foo / $bar )
  • Remainder: #set( $value = $foo % $bar )

    #if / #elseif / #else - output conditional on truth of statements鏉′歡鎺у埗璇彞

鏍煎紡錛欶ormat:

#if( [condition] ) [output] [ #elseif( [condition] ) [output] ]* [ #else [output] ] #end

鍏朵腑錛歎sage:

  • condition - 濡傛灉鏄竴涓猙oolean鐨勮瘽錛屽垯鏍規嵁鍊兼槸true鎴栬協alse鏉ュ垽鏂紝濡傛灉涓嶆槸涓涓猙oolean錛屽垯鏉′歡鐨勫間笉涓簄ull鍒欎負true銆侷f a boolean, considered true if it has a true false; if not a boolean, considered true if not null.
  • output - May contain VTL.

渚嬪瓙錛欵xamples:

  • 鐩哥瓑鎿嶄綔Equivalent Operator: #if( $foo == $bar )
  • 澶т簬Greater Than: #if( $foo > 42 )
  • 灝忎簬Less Than: #if( $foo < 42 )
  • 涓嶅皬浜嶨reater Than or Equal To: #if( $foo >= 42 )
  • 涓嶅ぇ浜嶭ess Than or Equal To: #if( $foo <= 42 )
  • 鐩哥瓑鐨勫糆quals Number: #if( $foo == 42 )
  • 鐩哥瓑鐨勫瓧絎︿覆Equals String: #if( $foo == "bar" )
  • 姹傚弽Boolean NOT: #if( !$foo )

    #foreach - Loops through a list of objects閬嶅巻涓涓垪琛?/h2>

鏍煎紡錛欶ormat:

#foreach( $ref in arg ) statement #end

鍏朵腑錛歎sage:

  • $ref - 閬嶅巻鍒楄〃鐨勫綋鍓嶅紩鐢ㄣ俆he first variable reference is the item.
  • arg - 涓涓垪琛?姣斿涓涓璞℃暟緇勶紝闆嗗悎錛宮ap)錛屾垨鑰呮暟緇勫垪琛紝鎴栬呰寖鍥存搷浣溿侻ay be one of the following: a reference to a list (i.e. object array, collection, or map), an array list, or the range operator.
  • 璇彞statement - 瀵規瘡嬈¢氳繃閬嶅巻寰楀埌鐨勪竴涓煎緱鎿嶄綔銆俉hat is output each time Velocity finds a valid item in the list denoted above as arg . This output is any valid VTL and is rendered each iteration of the loop.

涓嬮潰鏄渷鐣ヤ簡澶勭悊璇彞鐨?foreach()鐨勪緥瀛愶細Examples of the #foreach(), omitting the statement block :

  • 寮曠敤錛歊eference: #foreach ( $item in $items )
  • 鏁扮粍錛欰rray list: #foreach ( $item in ["Not", $my, "fault"] )
  • 鑼冨洿錛歊ange operator: #foreach ( $item in [1..3] )

Velocity鎻愪緵浜嗕竴涓畝鍗曠殑寰楀埌寰幆嬈℃暟鐨勬柟娉曪紝鎵浠ヤ綘鍙互鍍忎笅闈㈣繖鏍鋒搷浣滐細Velocity provides an easy way to get the loop counter so that you can do something like the following:

<table>
 #foreach( $customer in $customerList )

<tr>

<td>$velocityCount</td>

<td>$customer.Name</td>

</tr>

#end

</table>
榛樿鐨勮鏁扮殑鍙橀噺鏄?velocityCount錛屼笉榪囷紝浣犱篃鑳藉湪velocity.properties鏂囦歡涓繘琛岃嚜宸辯殑閰嶇疆銆傞粯璁ょ殑鎯呭喌涓嬶紝璁℃暟鍣ㄦ槸浠?寮濮嬬殑錛屼絾鏄繖涔熷彲浠ュ湪velocity.properties鏂囦歡涓繘琛岄厤緗紝涔熻兘浠?寮濮嬭鏁般備笅闈㈡槸鍦╲elocity.properties鏂囦歡涓璁℃暟鍣ㄧ殑鍚嶅瓧鍜岃搗濮嬪奸厤緗殑浠g爜鐗囨柇錛歍he default name for the loop counter variable reference, which is specified in the velocity.properties file, is $velocityCount. By default the counter starts at 1, but this can be set to either 0 or 1 in the velocity.properties file. Here's what the loop counter properties section of the velocity.properties file appears:

# Default name of the loop counter
# variable refernce.

counter.name = velocityCount

# Default starting value of the loop

# counter variable reference.

counter.initial.value = 1

#include -涓嶅姞瑙i噴鐨勫悎鎴愭湰鍦版枃浠禦enders local file(s) that are not parsed by Velocity

鏍煎紡錛欶ormat:

#include( arg[, arg2, ... argn] )

  • arg - Refers to a valid file under TEMPLATE_ROOT.

渚嬪瓙錛欵xamples:

  • String: #include( "disclaimer.txt", "opinion.txt" )
  • Variable: #include( $foo, $bar )

浠涔堝彨涓嶅姞瑙i噴?灝辨槸璇磛elocity鍙槸鎶婅繖涓枃浠剁殑鍐呭鐩存帴鍚堟垚鍒版寚瀹氱殑浣嶇疆錛岃屽鏋滃湪榪欎釜鏂囦歡涓篃鏈塚TL鐨勮鍙ワ紝鏄笉浼氱炕璇戠殑銆傚鏋滆瀹炵幇榪欎釜鍔熻兘錛岃鐢ㄥ埌涓嬮潰鐨?parse銆?/p>

#parse - 瑙i噴鐨勫悎鎴愭湰鍦版ā鐗圧enders a local template that is parsed by Velocity

鏍煎紡錛欶ormat:

#parse( arg )

  • arg - Refers to a template under TEMPLATE_ROOT.

渚嬪瓙錛欵xamples:

  • String: #parse( "lecorbusier.vm" )
  • Variable: #parse( $foo )

榪欓噷鍏佽閫掑綊鐨勮皟鐢ㄣ備綘鍙互鍦╲elocity.properties涓敼鍙?em>parse_directive.maxdepth 鐨勫兼潵紜畾鍏佽閫掑綊鐨勫眰鏁般傦紙榛樿鐨勫間負10錛塕ecursion permitted. See parse_directive.maxdepth in velocity.properties to change from parse depth. (The default parse depth is 10.)

#stop - 鍋滄妯$増寮曟搸Stops the template engine

鏍煎紡錛欶ormat:

#stop

Usage:

榪欎釜鏂規硶鑳藉仠姝㈡墽琛屽綋鍓嶇殑妯$増錛屽緢閫傚悎鐢ㄤ簬DEBUG銆俆his will stop execution of the current template. This is good for debugging a template.

#macro - 鍏佽鐢ㄦ埛瀹氫箟涓涓猇elocity瀹忥紙VM錛夛紝鑳介噸鐢ㄤ竴浜涙搷浣溿侫llows users to define a Velocimacro (VM), a repeated segment of a VTL template, as required

鏍煎紡錛欶ormat:

#macro( vmname $arg1 [ $arg2 $arg3 ... $argn ] ) [ VM VTL code... ] #end

  • vmname - 瀹忕殑鍚嶅瓧銆侼ame used to call the VM ( #vmname )
  • $arg1 $arg2 [ ... ] - 浼犻掔粰VM鐨勫弬鏁板垪琛ㄣ傚弬鏁扮殑涓暟涓嶉檺錛屼絾璋冪敤鏃跺欎紶鍏ョ殑鍙傛暟蹇呴』鍜屽畾涔夊畯鐨勬椂鍊欒瀹氱殑鍙傛暟涓暟鐩稿悓銆侫rguments to the VM. There can be any number of arguments, but the number used at invocation must match the number specified in the definition.
  • [ VM VTL code... ] - 鍚堟硶鐨刅TL浠g爜銆備換浣曡兘鏀懼湪妯$増涓殑浠g爜閮借兘鏀懼湪VM閲岄潰銆侫ny valid VTL code, anything you can put into a template, can be put into a VM.

濡傛灉瀹忎竴鏃﹀畾涔夛紝灝卞彲浠ュ儚涓嬮潰榪欐牱璋冪敤錛歄nce defined, the VM is used like any other VTL directive in a template.

#vmname( $arg1 $arg2 )
VM鍙互鍦ㄤ笅闈袱涓湴鏂瑰畾涔夛細VMs can be defined in one of two places:

  1. Template library: can be either VMs pre-packaged with Velocity or custom-made, user-defined, site-specific VMs; available from any template
  2. Inline: found in regular templates, only usable when velocimacro.permissions.allowInline=true in velocity.properties .

    娉ㄩ噴Comments

琚敞閲婁簡鐨勫唴瀹逛笉浼氳鍚堟垚銆侰omments are not rendered at runtime.

鍗曡鐨勬敞閲奡ingle Line

Example:

## This is a comment.

澶氳鐨勬敞閲奙ulti Line

Example:

#*
This is a multiline comment.
This is the second line
*#



鏈卞博 2007-04-05 23:50 鍙戣〃璇勮
]]>
Velocity鍦╓eb http://www.tkk7.com/zhuyan/articles/108819.html鏈卞博鏈卞博Thu, 05 Apr 2007 15:49:00 GMThttp://www.tkk7.com/zhuyan/articles/108819.htmlhttp://www.tkk7.com/zhuyan/comments/108819.htmlhttp://www.tkk7.com/zhuyan/articles/108819.html#Feedback0http://www.tkk7.com/zhuyan/comments/commentRss/108819.htmlhttp://www.tkk7.com/zhuyan/services/trackbacks/108819.html鐢╒elocity鏋勫緩涓涓猈eb搴旂敤

Velocity鍦ㄥ簲鐢ㄤ腑閫氬父鐢ㄤ簬鐢熸垚欏甸潰錛屾潵鐩存帴浠f浛JSP銆備竴浜涗嬌鐢╒elocity鏉ョ敓鎴怶eb欏甸潰鐨勫ソ澶勫涓嬶細Velocity is often used to generate web pages in applications, usually as a direct replacement for JSP. Some of the benefits of using Velocity to generate web pages are:

  • 綆鍗昐implicity -娌℃湁澶氬皯鎶鏈殑Web璁捐鑰呭氨鑳戒功鍐欒繖浜涢〉闈€?The pages can be written and maintained by non-technical web designers.
  • 瀹規槗緇存姢Ease of maintainance - 浣跨敤鎺ㄨ崘鐨凪VC寮鍙戞ā寮忥紝灝忕▼搴忥紙script錛変笉鍐嶅嚭鐜板湪Web欏甸潰涓係cripting is removed from web pages with the recommended MVC approach.
  • 瀵規柟娉曞拰灞炴х殑璁塊棶Access both methods and properties - Web璁捐鑰呭彲浠ヨ闂笂涓嬫枃涓竴涓璞$殑灞炴у拰鏂規硶銆俉eb designers can reference methods as well as properties of objects in a context.
  • 涓鑷存onsistency -Velocity鍙互琚敤浣滃叾浠栫殑鏂囨湰鐢熸垚宸ヤ綔錛堟瘮濡傚彂閫乪mail錛夛紝騫舵彁渚涗簡涓鑷寸殑鏍囪璇█銆?Velocity can be used for other text generation tasks (such as sending email) providing a consistent way to mark up text.

榪欑瘒鏂囨。涓彁渚涗簡涓浜涘皢Velocity鐢ㄤ簬Web搴旂敤涓殑鍩烘湰淇℃伅銆俆his document provides some basic info on getting started with Velocity in a web application.

浣跨敤涓涓鏋?/h1>

Velocity寮曟搸鐨勪富瑕佸姛鑳芥槸鍩轟簬涓涓ā鐗堢敓鎴愭枃鏈傚洜姝わ紝Velocity騫舵病鏈夊寘鍚換浣曚笌Web鐩稿叧鐨勫姛鑳姐俆he primary purpose of the Velocity engine is simply to generate text based on a template. Consequently, Velocity does not contain any web-related functionality in and of itself. 瑕佸垱寤轟竴涓猈eb搴旂敤錛屼綘闇瑕佷竴涓鏋舵潵鍝嶅簲HTTP璇鋒眰錛屽鐞嗙敤鎴瘋璇侊紝璋冪敤涓氬姟閫昏緫錛屽茍涓旇繑鍥炲搷搴斻俆o make a web application, you will need a framework to respond to HTTP requests, handle user authentication, make business logic calls, and generate a response. 涓嬮潰鏄竴浜涢潪甯稿己澶х殑鎻愪緵鑰呫俆here are several strong contenders.

  1. Velocity Tools / VelocityViewServlet - 鏈綆鍗曠殑寮濮嬬殑鏂規硶鏄笅杞絍elocity Tools瀛愰」鐩紝浣跨敤VelocityViewServlet銆傝繖涓猻ervlet鐨勯厤緗拰瀹夎閮藉緢綆鍗曘俆he easiest way to get started is to download the companion Velocity Tools subproject and use the VelocityViewServlet . This servlet is easy to configure and install.浣犻渶瑕佸湪web鏈嶅姟鍣ㄤ笂鍒涘緩涓涓ā鐗堢殑鐩綍錛屽茍緙栬緫涓涓寘鍚簡闇瑕佹斁緗湪涓婁笅鏂囦腑鐨?Tools"鐨勫垪琛ㄧ殑XML鏂囦歡灝辮浜嗐傚叿浣撶殑緇嗚妭璇峰弬瑙佷笅闈㈢殑鎸囧崡銆?You create a directory of templates on your web server, edit an XML file that lists various "Tools" to place in the context and you are off. More details can be found in the tutorial below.
  2. Velocity Tools / VelocityStruts - 涔熻浣犲嫻佽鐨凷truts妗嗘灦姣旇緝鐔熸倝銆係truts鏈寮濮嬫槸涓轟簡璁捐涓涓負JSP鎻愪緵鏇村鏈夌敤鐨勫姛鑳界殑搴旂敤銆俌ou may be familiar with the popular Struts framework, originally designed to provide much needed application functionality to JSP.鍦╒elocity Tools 鐨?span class=nobr>VelocityStruts妯″潡鐨勫府鍔╀笅錛屼綘鍙互鐢╒elocity浠f浛JSP浣滀負欏甸潰鐨勬ā鐗堣璦銆傝繖鍏佽浣犱嬌鐢⊿truts寮哄ぇ鐨勫熀紜璁炬柦鐨勫ソ澶勭殑鍚屾椂錛屼嬌鐢╒elocity璁捐欏甸潰銆?With the VelocityStruts module of Velocity Tools you can substitute Velocity for JSP as the page template language. This allows you to take advantage of the large base of Struts infrastructure while designing pages using Velocity.
  3. 絎笁鏂規鏋禩hird party frameworks - 榪樻湁璁稿鐨勭涓夋柟妗嗘灦鍦?span class=nobr>PoweredByVelocity wiki 欏甸潰涓娿俆here are a number of third party frameworks listed on the PoweredByVelocity wiki page. 鍦ㄥ叾涓紝Spring鍙兘鏄鍏鐨勬渶鍏堣繘鐨勬鏋朵簡銆侽f these, Spring is probably the most sophisticated and well known. Jakarta Turbine 鏈夎澶氱壒鐐瑰茍涓斾篃寰堟湁鐢紝瀹冨熀浜嶸elocity騫朵嬌鐢╒elocity浣滀負涓昏鐨勯〉闈㈣璦錛岃繖騫朵笉濂囨紝鍥犱負鏈夎澶歏elocity鐨勬棭鏈熷紑鍙戣呭湪寮鍙戝拰緇存姢瀹冦侸akarta Turbine has many features and can also be very useful. It was built with Velocity as the primary page language, which is not surprising since many of the original Velocity developers were involved in creating it.涓涓洿綆鍗曠殑閫夋嫨鏄疢averick妗嗘灦錛孧averick鎻愪緵浜嗕竴涓緢濂界殑闆嗘垚浜哣elocity鐨勭畝鍗曠殑鎺у埗鍣ㄧ粨鏋勶紝浣嗕粎姝よ屽凡銆?A simpler alternative is the Maverick framework which provides a simple Controller architecture that integrates nicely with Velocity but has no bells or whistles.
  4. 鏋勫緩浣犺嚜宸辯殑Build your own - 鏈鍚庣殑涓涓夋嫨鏄垱寤轟綘鑷繁鐨勬鏋躲侫 final alternative is to build your own framework.寤虹珛涓涓漿鍙憇ervlet錛圖ispatcher servlet錛夛紝浠庝竴涓枃浠舵垨鑰呮暟鎹簱涓绱㈠嚭妯$増錛岄泦鎴愪綘鑷繁鐨勫晢鍔¢昏緫錛屽茍榪斿洖緇撴灉緇欑敤鎴楓?Create a dispatcher servlet, retrieve templates from a file or database, integate with your business logic and send the results back to the user. 浠庝竴涓凡鏈夌殑妗嗘灦鍑哄彂騫舵墿灞曞畠閫氬父鏄竴鏇寸畝鍗曠殑鏂規硶銆傜壒鍒殑錛屼綘鍙渶瑕佷負VelocityViewServlet鍒涘緩涓涓瓙綾伙紝鏃㈣兘鍚戝叾涓坊鍔犳柊鐨勫姛鑳姐侽ften you'll have an easier time starting with one of the existing frameworks and customizing it. In particular you can add new functionality to the VelocityViewServlet simply by creating a subclass.

欏轟究涓鎻愶紝浣犲彲鑳藉伓鐒跺彂鐜?span class=nobr>VelocityServlet榪欎釜綾伙紝璇ュ璞℃槸涓涓湪Velocity 1.4鐗堟湰涓笉鎻愬′嬌鐢ㄧ殑servlet銆?span class=nobr>VelocityServlet宸茬粡涓嶅啀緇存姢錛屾墍浠ワ紝鎴戜滑寮虹儓寤鴻浣犱嬌鐢╒elocity Tools涓殑VelocityViewServlet銆侫s a side note, you may also come across references to VelocityServlet, which is a deprecated servlet that was included in the Velocity Engine up to version 1.4. Since VelocityServlet is no longer being maintained we strongly recommend you use VelocityViewServlet in Velocity Tools instead.

Web鏂歸潰鐨勯棶棰榃eb-Specific Issues

瀵逛簬Velocity鍦╳eb鐨勫簲鐢紝鏈変竴浜涢棶棰橀渶瑕佽璁恒傝繖浜涢兘鏄粡甯擱亣鍒扮殑闂涓殑涓浜涚畝鍗曠殑璁ㄨ銆俆here are a few issues with Velocity that are specific to web applications. Here is a brief discussion of the most commonly encountered issues.

涓嶈鏀瑰彉瀵硅薄鐨勭姸鎬丆hanging Object State - Don't!

鍦╒elocity涓紝濡傛灉灝嗕竴涓璞′綔涓轟竴涓紩鐢紝閭d箞Velocity鎻愪緵浜嗚闂瀵硅薄鐨勪換浣曟柟娉曠殑鑳藉姏銆傚湪欏甸潰涓樉紺轟俊鎭殑鏃跺欙紝榪欎釜鍔熻兘寰堟湁鐢紝浣嗘槸鍚屾椂濡傛灉瀵硅薄鎴栬呭簲鐢ㄧ殑鐘舵佽鏀瑰彉浜嗭紝榪欐牱鍋氫篃鏄緢鍗遍櫓鐨勩俈elocity provides the ability to call any method of an object acting as a reference. This can be useful when displaying information into the page but is dangerous when object or application state is modified.

涓句釜渚嬪瓙錛屼笅闈㈢殑浠g爜瀹夊叏鐨勮皟鐢ㄤ簡涓涓猯ist鐨剆ize()鏂規硶騫舵樉紺虹粨鏋溿侳or example, the following code safely calls the size() method of a list and displays the result.

There are $users.size() currently logged in.
涓涓笉瀹夊叏璋冪敤鐨勪緥瀛愶細鍦ㄤ竴涓儲鍔eb欏甸潰涓婏紝鍦ㄤ笂涓嬫枃涓殑涓涓璞¤兘璁$畻姣忎竴騫寸殑鏁版嵁銆傛柟娉昪alculateNextYear()鏂規硶鑳借綆椾笅涓騫寸殑鏁版嵁騫跺皢涓涓唴閮ㄧ殑璁℃暟鍣ㄥ仛澧炲姞鎿嶄綔銆侫n example of an unsafe operation concerns a financial web page with an object in the context that calculates data year by year. The method calculateNextYear() calculates data for the next year and advances an internal counter:

2005 data: $table.data
$table.calculateNextYear()

2006 data: $table.data
The problem with this approach is that the code cannot be repeated in multiple parts of the page. You may not intend to do so, but it's easy to forget this when cutting and pasting or writing control statements (such as #if or #foreach). This becomes more of an issue when you are dealing with application or session-level state.

鎴戜滑寮虹儓寤鴻鐨勫疄璺墊槸鍙嬌鐢╒elocity鍚戞枃鏈腑鎻掑叆淇℃伅銆傛柟娉曡皟鐢ㄤ細鏄緱鍒頒俊鎭殑涓涓湁鏁堢殑鏂規硶錛屼絾涓鑸鏉ヤ嬌鐢ㄤ竴涓柟娉曡皟鐢ㄦ潵鏀瑰彉瀵硅薄鐨勭姸鎬佹槸涓涓笉鑹殑瑙傚康錛屾潵鏀瑰彉搴旂敤鐨勭姸鎬佷竴瀹氭槸涓涓敊璇殑鎯蟲硶銆俆he (strongly) recommended practice is to only use Velocity for inserting information into text. Method calls can be useful to retrieve information. However, it's generally a bad idea to use a method call to change object state, and it's always a bad idea to change application state.

濡傛灉浣犲繀闇瑕佹敼鍙樺璞$殑鐘舵侊紙姣斿鍓嶉潰鐨勪緥瀛愶級錛屽彲浠ラ鍏堣綆楀嚭鎵鏈夊彲鑳界殑鍊煎茍鏀懼叆涓涓狶ist鎴栧垯Map瀵硅薄涓傛墍鏈夌殑瑕佹敼鍙樺簲鐢ㄧ殑鐘舵佺殑鍔ㄤ綔搴旇鎬繪槸鏀懼湪鎺у埗鍣ㄤ腑銆侷f you find yourself needing to change object state (as in the previous example) try precalculating all the possible values in the controller and putting them in a List or Map. Any changes to application state should always be done by the controller.

涓涓浉鍏崇殑娉ㄦ剰錛屼綘搴旇鍦ㄤ笂涓嬫枃瀵硅薄涓斁鍏ヤ竴涓狶ist鎴栬呬竴涓猄et瀵硅薄錛岃屼笉鏄斁鍏ヤ竴涓狪terator鎴栬匛numeration銆傝繖鏍峰厑璁擱泦鍚堝璞″湪娌℃湁鏀瑰彉鏃墮噸澶嶄嬌鐢ㄣ侽n a related note, you should always put a List or Set into the context instead of an Iterator or Enumeration. This allows the collection to be used more than once in the page with no change in behavior.

鍘繪帀HTML/XML鏍囪Escaping HTML/XML Entities

浠諱綍鐢ㄦ埛娣誨姞鐨勫甫鏈塇TML鎴栬匵ML鏍囪錛堟瘮濡?lt;,>,&錛夌殑鏂囨湰閮藉簲璇ュ湪濉埌web欏甸潰涔嬪墠琚幓鎺夈備負浜嗙‘淇濋〉闈㈡紜樉紺哄拰閬垮厤鍗遍櫓鐨勮法绔欑偣鑴氭湰錛坈ross-site scripting涓縐嶆敾鍑繪墜孌碉紝鍦ㄩ〉闈腑鍖呭惈鍙︿竴涓甫鏈夋湪椹殑欏甸潰錛夈備笉璞STL錛圝ava鏍囧噯鏍囪璇█錛夛紝Velocity涓嶅寘鍚幓闄TML鏍囪鐨勫姛鑳斤紝浣嗘槸浣犲彲浠ラ氳繃涓夌鏂規硶鏉ヨ揪鍒扮洰鐨勩侫ny user-entered text that contains special HTML or XML entities (such as <, >, or &) needs to be escaped before included in the web page. This is required, both to ensure the text is visible, and also to prevent dangerous cross-site scripting. Unlike, for example, JSTL (the Java Standard Tag Language found in Java Server Pages), Velocity does not contain any HTML-specific escaping functionality. However, you have three options:

  1. 鍒涘緩涓涓?Tool"錛屽茍涓斿寘鍚竴涓兘鍘繪帀HTML鏍囪鐨勬柟娉曘傛瘮濡?$escape.html($usertext)銆傝繖鏄渶綆鍗曠殑瑙e喅闂鐨勬柟娉曘侰reate a special "Tool" (an object in the context) with a method that performs escaping, for example $escape.html($usertext). This is conceptually the easiest way to solve this problem.
  2. 鍒涘緩涓涓嚜瀹氫箟鐨?span class=nobr>ReferenceInsertionEventHandler 錛岃兘鑷姩鐨勫幓鎺夋墍鏈夊紩鐢ㄤ腑鐨凥TML鏍囩銆傚鏋滄墍鏈夌殑寮曠敤涓殑鍐呭閮介渶瑕佽媯鏌ュ茍鍘繪帀HTML鏍囩錛岄偅涔堣繖鏍峰仛鏄渶鐪佷簨鐨勩侰reate a custom ReferenceInsertionEventHandler that automatically escapes every reference. If all references need to be escaped, this is the most painless method.
  3. 鍒涘緩涓涓嚜瀹氫箟鐨勬爣璇嗭紝姣斿#escape錛屾潵鍘繪帀鍦ㄨ鏍囪瘑瀵歸噷闈㈢殑鎵鏈夊紩鐢ㄤ腑鐨凥MTL鏍囩銆侰reate a custom directive (e.g. #escape) that escapes all text within the directive block.

娉ㄦ剰錛屾湁鏃跺欏叾浠栫殑鏍囪涔熼渶瑕佽鍘繪帀銆傛瘮濡傚湪CSS閲岄潰錛孈闇瑕佽鍘繪帀錛屽湪Javascript錛屽崟鐙殑'絎﹀彿闇瑕佷粠瀛楃涓蹭腑鍘繪帀鎴栨浛鎹€侼ote that other kinds of escaping are sometimes required. For example, in style sheets the @ character needs to be escaped, and in Javascript strings the single apostrophe ' needs to be escaped.

搴旂敤鐨勫畨鍏⊿ecuring the Application

褰撲竴涓獁eb搴旂敤鍦ㄦ湇鍔″櫒涓婂紑濮嬭繍琛屼簡錛屾湁浜嗚嫢騫茬殑鐢ㄦ埛鍜屼竴浜涘彈淇濇姢鐨勮祫婧愶紝榪欐椂鍊欙紝搴旂敤鐨勫畨鍏ㄦф柟闈㈢殑瑕佹眰灝辨樉鐜板嚭鏉ヤ簡銆俈elocity涓凡緇忔兜鐩栦簡澶у鏁版爣鍑嗙殑web瀹夊叏鎬ф爣鍑嗐備竴浜涚壒鍒殑闂錛堟瘮濡傜郴緇熼厤緗紝璺ㄧ珯鐐硅剼鏈紝鎴栬呮柟娉曡嚜鐪侊級絳夐兘鍦˙uilding Secure Applications with Velocity 榪欑瘒鏂囩珷涓婃湁鎵浠嬬粛銆係ince a web application is running on a central server, that typically has multiple users and confidential resources, care must be taken to make certain that the web application is secure. Most standard web security principles apply to a web application built with Velocity. A few specific issues (such as system configuration, more on cross-site scripting, and method introspection) are written up in this article on Building Secure Applications with Velocity.

鏃ュ織鏂囦歡Log Files

榪樻湁涓鐐瑰氨鏄疺elocity鍦ㄦ棩蹇楁柟闈㈢殑閰嶇疆姣旇緝緙轟箯銆備粬鎬繪槸鍦ㄥ綋鍓嶆枃浠跺す涓垱寤轟竴涓棩蹇楁枃浠躲傚綋Velocity鐢ㄥ湪Web搴旂敤涓殑鏃跺欙紝褰撳墠鏂囦歡澶規寚鐨勬槸搴旂敤寮濮嬬殑閭d釜鏂囦歡澶廣傚鏋滀綘鍙戠幇"velocity.log"榪欎釜鏂囦歡鍑虹幇鍦ㄤ綘鏂囦歡緋葷粺鐨勪笉鍥哄畾浣嶇疆錛岃媯鏌ヤ綘鐨刅elocity 鏃ュ織鐨勯厤緗備竴鑸儏鍐典笅錛屽嚭鐜拌繖涓棶棰樼殑鍘熷洜鏄湪闄や簡欏甸潰鐢熸垚涔嬪鐨勫叾浠栧湴鏂硅繕浣跨敤浜哣elocity錛堟瘮濡傚彂閫侀偖浠訛級銆侫 minor point is that Velocity, in the absence of any log-related configuration, creates a log file in the current directory. When Velocity is used in a web application the "current directory" is usually the current directory from which the application server is started. If you start seeing the file "velocity.log" files in random places on your server filesystem, check the Velocity log configuration. Typically this occurs when Velocity is used within a web application outside of web page generation (e.g. for sending email).

鎸囧崡Tutorial

涓嬮潰鏄竴涓粙緇嶄嬌鐢?a title=VelocityViewServlet >VelocityViewServlet鏉ュ緩绔嬩竴涓畝鍗曠殑web搴旂敤鐨勭畝瑕佹暀紼嬨傛洿澶氱殑淇℃伅璇峰弬瑙乂elocity Tools 鐨勬枃妗c俉hat follows is a brief tutorial on building a simple web app with VelocityViewServlet. For more information, consult the Velocity Tools documentation.

  1. 浠?download page 涓嬭澆Velocity Tools欏圭洰鐨勬簮浠g爜銆傞噷闈㈠寘鍚簡涓嬮潰浠嬬粛鐨勮繖涓緥瀛愮殑浠g爜銆侱ownload the Velocity Tools project source (you need the source for the examples) from download page .
  2. 璇風‘淇濅綘鐨?Apache Ant 鐜瀹夎姝g‘銆侷f you haven't already installed Apache Ant . do so now.
  3. 浣跨敤涓嬮潰鐨勬寚浠ゆ潵鏋勫緩VelocityTools鐨刯ar鍖呭拰"simple"紺轟緥銆侭uild the Velocity Tools jar and the "simple" example by typing: ant example.simple
  4. 瀵熺湅"examples"鏂囦歡澶癸紝鍦ㄩ噷闈綘浼氬彂鐜頒竴涓彨"index.vm"鐨勬枃浠訛紝涓嬮潰鏄繖涓枃浠剁殑鎽樺綍錛歍ake a look at the "examples" directory. You will see a file "index.vm". Here's an excerpt: <html> <body> I'm a velocity template.
    #if( $XHTML )
    #set( $br = "<br />" )
    #else
    #set( $br = "<br>" )
    #end
    $br $br
    Here we use a custom tool: $toytool.message
    $br $br
    Here we get the date from the DateTool: $date.medium
    </body>
    </html>
    浣犲彲浠ュ鍒跺叾浠栫殑velocity妯$増鏂囦歡鍒拌繖涓枃浠跺す閲岄潰銆傚湪examples/WEB-INF鏂囦歡澶逛笅錛屼綘浼氬彂鐜頒竴涓?toolbox.xml"鏂囦歡錛屽湪榪欎釜鏂囦歡閲岄潰灝卞畾涔変簡鑷姩鏀懼湪Velocity涓婁笅鏂囦腑鐨勫璞$殑鍒楄〃銆俌ou can copy any additional velocity files into this same directory. In examples/WEB-INF you will see a file "toolbox.xml". This specifies a list of "Tools" that are automatically included in the context. <toolbox> <xhtml>true</xhtml>
    <tool>
    <key>toytool</key>
    <class>ToyTool</class>
    </tool>
    <data type="number">
    <key>version</key> <value>1.1</value>
    </data>
    <data type="boolean">
    <key>isSimple</key> <value>true</value>
    </data>
    <data type="string">
    <key>foo</key> <value>this is foo.</value>
    </data>
    <data type="string">
    <key>bar</key> <value>this is bar.</value>
    </data>
    <tool>
    <key>map</key>
    <class>java.util.HashMap</class>
    </tool>
    <tool>
    <key>date</key>
    <scope>application</scope> <class>org.apache.velocity.tools.generic.DateTool</class> </tool>
    </toolbox>  
    鏈鍚庯紝搴旂敤鐨剋eb.xml鏂囦歡閲岄潰瀹氫箟浜嗘帴鍙楄姹傜殑servlet鍜宼oolbox鐨勯厤緗枃浠朵綅緗侫nd finally the web.xml file specifies the name of the servlet and location of toolbox.properties. <web-app> <servlet>
    <servlet-name>velocity</servlet-name>
    <servlet-class> org.apache.velocity.tools.view.servlet.VelocityViewServlet </servlet-class>
    <init-param>
    <param-name>org.apache.velocity.toolbox</param-name>
    <param-value>/WEB-INF/toolbox.xml</param-value> </init-param>
    <load-on-startup>10</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.vm</welcome-file>
    </welcome-file-list>
    </web-app>
  5. 灝嗚繖涓枃浠跺す鎷瘋礉鍒頒綘Tomcat鐨剋ebapps鏂囦歡澶逛笅錛岃鎷瘋礉鏁翠釜鏂囦歡澶癸紙鑰屼笉鍏夋槸simple.war錛変細璁╀綘鏇村鏄撻氳繃鏀瑰彉鎴栬呮坊鍔犱竴浜涗笢瑗挎潵鍋氫簺瀹為獙銆傜幇鍦紝浣犲彲浠ラ氳繃涓嬮潰鐨勫湴鍧鏉ヨ闂〉闈簡銆傦紙鍦板潃闅忕潃浣犵殑欏圭洰鐨勫悕瀛楁敼鍙橈級Copy this directory into your "webapps" directory on Tomcat. You could also copy "simple.war", but copying in the entire directory will let you experiment with changes. You should now be able to access your simple one-page webapp with this URL. (or something similar): http://localhost:8080/simple/index.vm
  6. 灝濊瘯娣誨姞涓浜涙柊鐨刅elocity欏甸潰銆傛敞鎰忥紝浣犲彧闇瑕佹敼鍙樿闂殑URL鍦板潃灝卞彲浠ヨ闂柊鐨勯〉闈簡銆傚皾璇曟敼鍙榯oolbox.xml涓殑涓浜涘唴瀹癸紝鎴栬呭悜鍏朵腑娣誨姞浣犺嚜宸辯殑Tools銆傚療鐪媏xamples/WEB-INF鐨勬枃妗o紝鎴栬匴iki 鏉ュ緱鍒版洿澶氱殑宸ュ叿鐨勪嬌鐢ㄤ俊鎭侲xperiment with adding new Velocity pages. Note that you can access any velocity page just by changing the URL. Try changing the entries in toolbox.xml or creating your own tools. Consult the Velocity Tools documentation and the Wiki for more info on the wide variety of tools available.


鏈卞博 2007-04-05 23:49 鍙戣〃璇勮
]]>
Velocity寮鍙戣呮寚鍗?/title><link>http://www.tkk7.com/zhuyan/articles/108818.html</link><dc:creator>鏈卞博</dc:creator><author>鏈卞博</author><pubDate>Thu, 05 Apr 2007 15:48:00 GMT</pubDate><guid>http://www.tkk7.com/zhuyan/articles/108818.html</guid><wfw:comment>http://www.tkk7.com/zhuyan/comments/108818.html</wfw:comment><comments>http://www.tkk7.com/zhuyan/articles/108818.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/zhuyan/comments/commentRss/108818.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/zhuyan/services/trackbacks/108818.html</trackback:ping><description><![CDATA[     鎽樿: 姒傝堪鍜屽叆闂↖ntroduction and Getting Started 璧勬簮Resources Velocity鎬庢牱宸ヤ綔How Velocity Works 鍩烘湰鐨勬牸寮廡he Fundamental Pattern 浣跨敤Singleton榪樻槸涓嶄嬌鐢═o Singleton Or Not To Singleton... ...  <a href='http://www.tkk7.com/zhuyan/articles/108818.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/zhuyan/aggbug/108818.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/zhuyan/" target="_blank">鏈卞博</a> 2007-04-05 23:48 <a href="http://www.tkk7.com/zhuyan/articles/108818.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Velocity浣跨敤鑰呮寚鍗?/title><link>http://www.tkk7.com/zhuyan/articles/108693.html</link><dc:creator>鏈卞博</dc:creator><author>鏈卞博</author><pubDate>Thu, 05 Apr 2007 06:35:00 GMT</pubDate><guid>http://www.tkk7.com/zhuyan/articles/108693.html</guid><wfw:comment>http://www.tkk7.com/zhuyan/comments/108693.html</wfw:comment><comments>http://www.tkk7.com/zhuyan/articles/108693.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/zhuyan/comments/commentRss/108693.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/zhuyan/services/trackbacks/108693.html</trackback:ping><description><![CDATA[     鎽樿: 鐩綍 鍏充簬鏈寚鍗? Velocity鏄粈涔? Velocity鑳戒負鎴戜滑鍋氫粈涔堬紵What can Velocity do for me? The Mud Store example Velocity妯$増璇█錛圴TL錛?鍏ラ棬Velocity Template Language (VTL): An Introducti...  <a href='http://www.tkk7.com/zhuyan/articles/108693.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/zhuyan/aggbug/108693.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/zhuyan/" target="_blank">鏈卞博</a> 2007-04-05 14:35 <a href="http://www.tkk7.com/zhuyan/articles/108693.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://ygloka.com" target="_blank">久久乐国产综合亚洲精品</a>| <a href="http://bearsou.com" target="_blank">亚洲婷婷第一狠人综合精品</a>| <a href="http://118762.com" target="_blank">日韩大片在线永久免费观看网站</a>| <a href="http://3789re.com" target="_blank">嫩草影院免费观看</a>| <a href="http://caoporg.com" target="_blank">亚洲国产欧美国产综合一区 </a>| <a href="http://m0808dy.com" target="_blank">久久亚洲免费视频</a>| <a href="http://selangcun.com" target="_blank">亚洲AV日韩精品久久久久久</a>| <a href="http://5r7b.com" target="_blank">久久一区二区三区免费播放</a>| <a href="http://26672814.com" target="_blank">亚洲国产精品久久久久久</a>| <a href="http://8mav938.com" target="_blank">女人18毛片免费观看</a>| <a href="http://bjowj.com" target="_blank">亚洲免费福利在线视频</a>| <a href="http://xyxpx.com" target="_blank">在线免费观看污网站</a>| <a href="http://fenglibin.com" target="_blank">亚洲精华液一二三产区</a>| <a href="http://gw311.com" target="_blank">mm1313亚洲国产精品美女</a>| <a href="http://sewuji.com" target="_blank">久久亚洲国产中v天仙www</a>| <a href="http://jinmenonline.com" target="_blank">亚洲人成网站色7799</a>| <a href="http://zcrencai.com" target="_blank">国产嫩草影院精品免费网址</a>| <a href="http://1880531.com" target="_blank">亚洲爆乳无码专区www</a>| <a href="http://88bgbg.com" target="_blank">一本久久综合亚洲鲁鲁五月天</a>| <a href="http://xiaochidaquan.com" target="_blank">香港特级三A毛片免费观看</a>| <a href="http://bjgelinhotel.com" target="_blank">亚洲一区二区高清</a>| <a href="http://2828228.com" target="_blank">免费人妻无码不卡中文字幕系</a>| <a href="http://szwangzhongwang.com" target="_blank">97se亚洲综合在线</a>| <a href="http://51a88.com" target="_blank">成年女人毛片免费播放人</a>| <a href="http://www-c559.com" target="_blank">国产亚洲女在线线精品</a>| <a href="http://023npxyy.com" target="_blank">亚洲午夜无码久久久久</a>| <a href="http://tzkanglong.com" target="_blank">a拍拍男女免费看全片</a>| <a href="http://zzo8.com" target="_blank">亚洲精品色播一区二区 </a>| <a href="http://hbtelong.com" target="_blank">久久国产乱子伦精品免费看</a>| <a href="http://yongyihongze.com" target="_blank">亚洲免费闲人蜜桃</a>| <a href="http://wyj4.com" target="_blank">91免费人成网站在线观看18</a>| <a href="http://schygfz.com" target="_blank">欧洲 亚洲 国产图片综合</a>| <a href="http://717795.com" target="_blank">亚洲精品麻豆av</a>| <a href="http://g8zb.com" target="_blank">222www免费视频</a>| <a href="http://oakuu.com" target="_blank">国产亚洲福利精品一区二区</a>| <a href="http://788qj.com" target="_blank">亚洲av综合av一区</a>| <a href="http://www-095666.com" target="_blank">成人免费看片又大又黄</a>| <a href="http://k67m.com" target="_blank">中国内地毛片免费高清</a>| <a href="http://jte-sh.com" target="_blank">精品久久久久久亚洲精品</a>| <a href="http://bjyaao.com" target="_blank">亚洲免费日韩无码系列</a>| <a href="http://733807.com" target="_blank">免费在线观看视频网站</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>