I have a problem in nodejs, see if any one could help me out.
I have a page.html to which I need to pass a param with value like
page.html?s=1
I am not able to send it, when I send it I am taken to a blank page.
server.js looks like the following:
var app = require('http');
var fs = require('fs');
var path = require('path');
var url = require('url') ;
var http = app.createServer(function handler(request, response) {
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
case '.json':
contentType = 'application/json';
break;
case '.png':
contentType = 'image/png';
break;
case '.jpg':
contentType = 'image/jpg';
break;
case '.wav':
contentType = 'audio/wav';
break;
case '.xml':
contentType = 'text/xml';
break;
}
fs.readFile(filePath, function (error, content) {
if (error) {
if (error.code == 'ENOENT') {
fs.readFile('./404.html', function (error, content) {
response.writeHead(200, {'Content-Type': contentType});
response.end(content, 'utf-8');
});
}
else {
response.writeHead(500);
response.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n');
response.end();
}
}
else {
response.writeHead(200, {'Content-Type': contentType});
response.end(content, 'utf-8');
}
});
}).listen(3100);
console.log('Server started at 3100');
Let me know if you need more info.
您所做的称为查询字符串, url parameter
为page.html/:something
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.