2018-12-06 node.js--第五天

const express=require('express');
const expressStatic=require('express-static');
var server=express();
server.listen(8080);
server.use(expressStatic('./www'))


    
        
        
    
    
        

用户名:

密码:



    
        
        
    
    
        

NCKLSDJGL

const express=require('express');
const expressStatic=require('express-static');
var server=express();
server.listen(8080);
server.use('/',function(req,res){
    console.log(req.query);//解析get发送的数据请求
})
server.use(expressStatic('./www'));

验证

//127.0.0.1:8080/login?uname=xxx&upwd=123    get 响应对象
//{
//  "ok":true/false,
//  "msg":用户名不存在
//}
//1.创建服务
const express=require('express');
//2.创建静态文件目录
const expressStatic=require('express-static');
var server=express();
server.listen(8080);
//4.模拟数据
var users={
    "blue":'123',
    "jack":'456',
    "tom":'789'
};

//3.处理用户请求
server.use('/login',function(req,res){
    //req.query  {uname:jack,upwd:123}
    console.log(req.query); //{uname:jack,upwd:123}
    //获取表单中的用户名和密码
    var user=req.query['uname'];
    //console.log(user)
    var upwd=req.query['upwd'];
    //console.log(upwd);
    if(users[user]==null){
        console.log(users[user]); //jack
        res.send({'ok':false,'msg':'用户名不存在'})
    }else if(users[user]!=upwd){
        res.send({'ok':false,'msg':'密码错误'})
    }else{
        res.send({'ok':true,'msg':'登陆成功'})
    }
})
server.use(expressStatic('./www'));



    
        
        
    
    
        

用户名:

密码:

你可能感兴趣的:(2018-12-06 node.js--第五天)