zoukankan      html  css  js  c++  java
  • go 表单

    
    package main
    import (
    	"fmt"
    	"io"
    	"net/http"
    )
    
    const form = `<html><body><form action="#" method="post" name="bar">
                        <input type="text" name="in"/>
                        <input type="text" name="in"/>
                         <input type="submit" value="Submit"/>
                 </form></html></body>`
    
    func SimpleServer(w http.ResponseWriter, request *http.Request) {
    	n, err := io.WriteString(w, "<h1>hello, world</h1>")
    	if err != nil{
    		fmt.Println(n)
    	}
    }
    
    func FormServer(w http.ResponseWriter, request *http.Request) {
    	w.Header().Set("Content-Type", "text/html")
    	switch request.Method {
    	case "GET":
    		io.WriteString(w, form)
    	case "POST":
    		request.ParseForm()
    		io.WriteString(w, request.Form["in"][0])
    		io.WriteString(w, "
    ss")
    		io.WriteString(w, request.FormValue("in"))
    	}
    }
    
    func Test(w http.ResponseWriter, r *http.Request){
    	fmt.Println("handler hello")
    	n, err := fmt.Fprintf(w, "hello world!")
    	fmt.Println(n)
    	if err != nil{
    		fmt.Println("write error:", n)
    	}
    }
    
    func main() {
    	http.HandleFunc("/", Test)
    	http.HandleFunc("/test1", SimpleServer)
    	http.HandleFunc("/test2", FormServer)
    	if err := http.ListenAndServe("127.0.0.1:80", nil); err != nil {
    		fmt.Println("http listen eror")
    	}
    }
    
    
  • 相关阅读:
    C#中方法的分类、定义、调用(3)
    C#中的输入和输出与类和对象(2)
    .net中的数据类型与数据转换(1)
    android第二章控件2
    android第二章控件1
    安卓 第一章
    二进制文件的读写与小结
    字符流
    File类与字节流
    字节流
  • 原文地址:https://www.cnblogs.com/lajiao/p/10895731.html
Copyright © 2011-2022 走看看