<code class="lang-">
//访问地址:http://localhost:8080/
//貌似其实可以全部写成一行的... -_-||
var http=require('http');
var url=require('url');
var express=require('express');
var session=require('express-session');
var bodyParser=require("body-parser");
var app = express();
var server = app.listen(8080, function () {});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({secret: '123456',name: 'session',cookie: {maxAge: 3600000},resave: false,saveUninitialized: true}));
app.get('/', function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<html><meta charset="UTF-8"><body><form action="/sub" method="post"><input name="t" type="text"> <input type="submit"></form></body></html>');
res.end();
});
app.post('/sub',function(req,res){
req.session.text=req.body.t;
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<html><meta charset="UTF-8"><body><a href=/text>请点这里</a></body></html>');
res.end();
});
app.get('/text',function(req,res){
res.writeHead(200, {'Content-Type': 'text/html'});
if(req.session.text!=null)
res.write('<html><meta charset="UTF-8"><body>'+req.session.text+'</body></html>');
else
res.write('<html><meta charset="UTF-8"><body>....</body></html>');
res.end();
});
</code>