login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="http://localhost:3000/login">//这里是url路径,methods应该为get
userName:<input type="text" name="userName"><br>
pass: <input type="text" name="pass"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
register.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="http://localhost:3000/regist"> userName:<input type="text" name="userName"><br> pass: <input type="text" name="pass"><br> <input type="submit" value="提交"> </form> </body> </html>
router.js
var http=require("http")//加载http协议 var url=require("url") http.createServer(function (req,res) {//创建服务器 res.writeHead(200,{"content-type":"text/html;charset=UTF-8"}); res.write("aaa end!"+req.url+"<br>"); console.log(req.url); var str=url.parse(req.url,true); console.log(str) if (str.pathname==="/login"){ res.write("userName="+str.query.userName) } if (str.pathname==="/regist"){ res.write("userName="+str.query.userName) } res.end(); }).listen(3000,"localhost")