##velocity最簡環境搭建 直接來步驟了:html
到官網下載安裝包(目前最新包連接以下)web
velocity-1.7.zipapache
在Eclipse裏面建立動態web工程url
要添加的jar包有兩部分,將如下內容拷貝到新工程的WebContent\WEB-INF\libcode
在WebContent目錄下添加 index.vm,內容以下:xml
#set($hello="Velocity") <html> <head> <title>Hello</title> </head> <body> Hello $hello World ! </body> </html>
修改web.xmlhtm
<servlet> <servlet-name>velocityView</servlet-name> <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>velocityView</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.vm</welcome-file> </welcome-file-list>
運行程序,能看到ip
說明運行成功ci
注意:
添加velocity-tools-2.0.zip 包裏面 lib下全部jar包而不是velocity-1.7.zip包lib下的全部jar包
在WebContent目錄下添加 index.vm,層級有時候容易看錯,好比你加到WEB-INF文件夾下的話,就會一直報錯說找不到index。
搭建環境的時候tool.xml暫時是不須要的,須要的時候再往裏面添加,這裏是最簡環境