處理靜態檔案
對于 HTML 頁面中的 css 以及 js 等靜態檔案,需要使用使用 net/http 包下的以下
方法來處理
-
StripPrefix 函式
-
FileServer 函式
-
例如:
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
/static/會匹配 以/static/開發的路徑,當瀏覽器請求index.html頁面中的
style.css檔案時,static前綴會被替換為views/staic,然后去views/static/css
目錄中取查找style.css檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/49392.html
標籤:Go
下一篇:java web后臺往前臺傳資料時候,我是在sevrlet里面運用List顯示到jsp頁面里面,但是顯示不出來資料庫庫資訊
