login.html
复制代码 代码如下:
<html>
<head><title></title></head>
<body>
<form action="http://localhost:9090/login" method="post">
用户名:<input type="text" name="username">
密 码:<input type="text" name="password">
<input type="submit" value="登录">
</form>
</body>
</html>
main.go
复制代码 代码如下:
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"strings"
)
func sayHelloName(w http.ResponseWriter, r *http.Request) {
// 解析url传递的参数
r.ParseForm()
//在服务端打印信息
fmt.Println(r.Form)
fmt.Println("path", r.URL.Path)
fmt.Println("Scheme", r.URL.Scheme)
fmt.Println(r.Form["url_long"])
for k, v := range r.Form {
fmt.Println("key:", k)
// join() 方法用于把数组中的所有元素放入一个字符串。
// 元素是通过指定的分隔符进行分隔的
fmt.Println("val:", strings.Join(v, ""))
}
// 输出到客户端
fmt.Fprintf(w, "hello astaxie!")
}
func login(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
if r.Method == "GET" {
t, _ := template.ParseFiles("login.html")
// 执行解析模板
// func (t *Template) Execute(wr io.Writer, data interface{}) error {
t.Execute(w, nil)
} else {
r.ParseForm()
fmt.Println("username:", r.Form["username"])
fmt.Println("password:", r.Form["password"])
}
}
func main() {
//设置访问路由
http.HandleFunc("/", sayHelloName)
http.HandleFunc("/login", login)
//设置监听端口
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndserve:", err)
}
}
以上所述就是本文的全部内容了,希望大家能够喜欢。
go语言,表单
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- dnf龙袍套装属性与天空套对比
- 横山菁儿-三国志-燃烧的长江-1993-APE整轨
- [ABC唱片]-《李传韵-琴魂》[K2-018][K2CD]WAV+CUE
- 【ABC唱片】《黃河號子SACD-011》-WAV分轨
- 当《生化危机2:重制版》加入路径追踪:画面真实感显著提升!
- 《哈迪斯2》BOSS不让暂停惹恼玩家:我手柄没电了!
- 《美末》S2艾莉造型首曝:头发留长 成熟了不少
- 邰正宵.2024-重燃爱恋.贰Walk.On【福茂】【FLAC分轨】
- 叶凡.2007-相思【中唱】【WAV+CUE】
- 王永.1997-十二道金牌【鸿心工作室】【WAV+CUE】
- dnf110换装在哪刷
- dnf110新版buff换装在哪里做
- dnf110满级了去哪里刷史诗
- 群星2024《龙年精逊纯银CD[WAV+CUE]
- 刘月宁《扬琴独奏-木兰辞变奏曲》[FLAC+CUE]