简单的服务器 实现引用css、js和a链接可以跳转
2017-07-07 17:05
489 查看
Go语言后台实现简单接口,使用Golang程序加载css、js支持浏览器查看
服务端代码:
Server.go
========== Vercity 文件夹的 index.html 这样写===================
========== RegOpration文件夹的 index.html 这样写 ===================
Vercity文件夹(含有CSS文件、index.html文件、images图片文件)
RegOpration文件夹(含有CSS文件、index.html文件、images图片文件),保证Vercity文件夹和RegOpration文件夹和main.go文件在同一目录下
至于对应的CSS文件自己定制就可以了。
+++++++++++++++++ 直观图示 ++++++++++++++++++
Login页面:
Register页面:
服务端代码:
Server.go
package main import ( "fmt" "log" "net/http" "github.com/go-http-utils/cors" ) func main() { httpServeMux := http.NewServeMux() httpServeMux.HandleFunc("/upload", Login) httpServeMux.HandleFunc("/register", Register) httpServeMux.Handle("/Vercity/", http.StripPrefix("/Vercity/", http.FileServer(http.Dir("Vercity")))) //添加html文件 httpServeMux.Handle("/RegOpration/", http.StripPrefix("/RegOpration", http.FileServer(http.Dir("RegOpration")))) //添加 a 链接html文件 fmt.Println("服务已启动...") Corshandler := cors.Handler(httpServeMux, cors.SetMethods([]string{"GET", "POST", "JBA"})) err := http.ListenAndServe(":8000", Corshandler) if err != nil { log.Fatal(err) } } func checkErr(err error) { //错误处理 if err != nil { log.Println(err) } } func Login(w http.ResponseWriter, r *http.Request) { //响应 Login 函数 userName := r.FormValue("username") passwd := r.FormValue("userpasswd") fmt.Println(userName) fmt.Println(passwd) } func Register(w http.ResponseWriter, r *http.Request) { //响应 Register 函数 username := r.FormValue("r_username") passwd := r.FormValue("r_userpasswd") passwd_ag := r.FormValue("ra_userpasswd") mail := r.FormValue("ra_email") fmt.Println(username) fmt.Println(passwd) fmt.Println(passwd_ag) fmt.Println(mail) }
========== Vercity 文件夹的 index.html 这样写===================
<!DOCTYPE HTML> <html> <head> <title>认证登录</title> <link href="assets/css/style.css" rel="stylesheet" type="text/css" media="all"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="keywords" content="登录" /> </head> <body> <!--header start here--> <div class="login-form"> <h1>登录</h1> <div class="login-top"> <form action="/upload" method="post" enctype="multipart/form-data"> <div class="login-ic"> <i ></i> <input type="text" name="username"}/> <div class="clear"> </div> </div> <div class="login-ic"> <i class="icon"></i> <input type="password" name="userpasswd"}/> <div class="clear"> </div> </div> <div class="log-bwn"> <input type="submit" value="Login" > </div class="log-bwn"> <div class="regist-link"><a href="//127.0.0.1:8000/Yxx/" clstag="pageclick|keycount|201607144|8" target="_blank" style="outline: 0px none rgb(109, 109, 109);"><b></b>立即注册</a></div> // 此处即为 a 链接 </div> </form> </div> </div> <!--header start here--> </body> </html>
========== RegOpration文件夹的 index.html 这样写 ===================
<!DOCTYPE HTML> <html> <head> <title>个人注册</title> <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="keywords" content="注册" /> </head> <body> <!--header start here--> <div class="login-form"> <h1>注册</h1> <div class="login-top"> <form action="/register" method="post" enctype="multipart/form-data"> <div class="form-item form-item-account" id="form-item-account"> <label>用 户 名</label> <input type="text" name="r_username"}/> <div class="clear"> </div> </div> <div class="form-item"> <label>设 置 密 码</label> <input type="text" name="r_userpasswd"} /> <div class="clear"> </div> </div> <div class="form-item"> <label>确 认 密 码</label> <input type="text" name="ra_userpasswd"} /> <div class="clear"> </div> </div> <div class="form-item"> <label>注 册 邮 箱</label> <input type="text" name="ra_email"}/> <div class="clear"> </div> </div> <div> <input type="submit" class="btn-register" value="Register" > </div> </form> </div> </div> <!--header start here--> </body> </html>
Vercity文件夹(含有CSS文件、index.html文件、images图片文件)
RegOpration文件夹(含有CSS文件、index.html文件、images图片文件),保证Vercity文件夹和RegOpration文件夹和main.go文件在同一目录下
至于对应的CSS文件自己定制就可以了。
+++++++++++++++++ 直观图示 ++++++++++++++++++
Login页面:
Register页面:
相关文章推荐
- tomcat服务器下使用nginx实现最简单的动静分离--解决css、js不加载的问题
- 自己总结的CSS以及JS各种库的在线CDN引用地址,链接可以直接复制(不定期更新)
- tomcat服务器下使用nginx实现最简单的动静分离--解决css、js不加载的问题
- BSP中如何引用外部文件(JS/CSS等)及复杂功能的组织实现
- 利用js+css简单实现半透明遮罩弹窗
- css简单实现热点链接
- 下面简单使用Jquery来操作iframe的一些记录,这个使用纯JS也可以实现。
- Node.js 实现简单的接口服务器
- css简单实现热点链接当鼠标悬停时出现白色的框
- CSS实现超级链接需要通过双击后跳转
- js+css实现的简单易用兼容好的分页
- JS+CSS简单实现DIV遮罩层显示隐藏
- Firefox 插件 JSview是一套比较实用的JS,CSS文件查看工具,很方便,很快捷地查看页面引用了哪些文件,作为Web前端开发者是一套必备的插件,由于Firefox升级过快,插件很快不兼容了,这里对插件做了一些调整,可以兼容最新Firefox浏览器(目前FireFox 21)
- CSS实现超级链接需要通过双击后跳转
- js+css简单实现半透明遮罩弹窗
- JS+CSS简单实现DIV遮罩层显示隐藏
- 利用css和js实现页面的标签效果。(标签个数可以动态变化)
- js+css实现的简单易用兼容好的分页
- css+js简单实现126邮箱注册页面