1. 如何在html 中显<img src ="" /a/xx.jpg""> 图片之类的?html
启用静态服务器 : 如:golang
http.handle("/", http.FileServer(http.Dir("/a"))) : 包含/a 的缘由是开启/a 目录下的访问权限。这样则在html 中 就能访问到/a/xx.jpg。浏览器
2. 解析html 页面, href 中含有中文, 下载问题?服务器
{{range .name}} <a href="{{.}}"><img src="download.jpg"></a></br> {{end}}
a) :当template 解析上段代码时, {{.}} 假设 被 "你好.txt" 给取代, 当在浏览器显示源码时, href=%e4%bd%a0%e5%a5%bd ,被自动编码。 编码
b): 当点击连接 href=%e4%bd%a0%e5%a5%bd 时, 提交给golang 服务器须要先将url 转换成字符串, 再 使用url.QueryUnescape() 进行解码。 这样就能在后台显示对应的中文路径或者资源。如:url
photoname := strings.TrimPrefix(r.URL.String(), "/") photoname, err := url.QueryUnescape(photoname)
获得的photoname值: 你好.txt. ^.^code