Update 04.1.md

登陆改成了登录
This commit is contained in:
言十年
2017-09-28 13:00:44 +08:00
committed by GitHub
parent af90cc4778
commit 049855991b

View File

@@ -11,12 +11,12 @@
<form action="/login" method="post">
用户名:<input type="text" name="username">
密码:<input type="password" name="password">
<input type="submit" value="登">
<input type="submit" value="登">
</form>
</body>
</html>
```
上面递交表单到服务器的`/login`,当用户输入信息点击登之后,会跳转到服务器的路由`login`里面我们首先要判断这个是什么方式传递过来POST还是GET呢
上面递交表单到服务器的`/login`,当用户输入信息点击登之后,会跳转到服务器的路由`login`里面我们首先要判断这个是什么方式传递过来POST还是GET呢
http包里面有一个很简单的方式就可以获取我们在前面web的例子的基础上来看看怎么处理login页面的form数据
```Go
@@ -51,7 +51,7 @@ func login(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("login.gtpl")
log.Println(t.Execute(w, nil))
} else {
//请求的是登数据,那么执行登的逻辑判断
//请求的是登数据,那么执行登的逻辑判断
fmt.Println("username:", r.Form["username"])
fmt.Println("password:", r.Form["password"])
}