[英]How to navigate to another html page?
In my application there's a usual login page sending username and password to the server script, where it needs to be authenticated, and in case of an authentic user, the server should redirect to a page student.html. 在我的应用程序中,有一个通常的登录页面,该页面将用户名和密码发送到服务器脚本,该脚本需要进行身份验证,如果用户是真实用户,则服务器应重定向到页面student.html。 This is my code 这是我的代码
var ports = 3000;
var portt = 3001;
var express = require('express');
var student = require('express')();
var teacher = require('express')();
var server_s = require('http').createServer(student);
var server_t = require('http').createServer(teacher);
var ios = require('socket.io').listen(server_s);
var iot = require('socket.io').listen(server_t);
var path = require('path');
server_s.listen(ports);
server_t.listen(portt);
student.use(express.static(path.join(__dirname, 'public')));
student.get('/', function(req,res){
res.sendfile(__dirname + '/login.html');
});
teacher.use(express.static(path.join(__dirname, 'public')));
teacher.get('/', function(req,res){
res.sendfile(__dirname + '/mytry.html');
});
ios.sockets.on('connection', function(socket){
var username, password;
socket.on('check',function(data){
username = data[0];
password = data[1];
//************* Database connection and query *************
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password: '*******',
database: 'my_db'
});
connection.connect();
var qstring = 'SELECT s_id FROM login_student WHERE username='+username+'AND password='+password;
connection.query(qstring, function(err, rows, fields)
{
if (err)
{
console.log('ERROR: ' + err);
socket.emit('login_failure','DB error');
return;
}
console.log('The solution is: ', rows[0].solution);
if (rows>0)
//***** Here i want redirection to another page ******
else socket.emit('login_failure','Invalid Username or password');
});
connection.end();
});
});
iot.sockets.on('connection', function(socket){
;
});
});
Can anyone suggest what should I do? 谁能建议我该怎么办?
One way is to send a redirection header in the response. 一种方法是在响应中发送重定向标头。 Add the following in place of your comment. 在您的评论中添加以下内容。
response.setHeader('Location','your_redirection_url');
Read : http://nodejs.org/docs/v0.4.12/api/http.html#response.setHeader One other way is to use meta redirect. print this as part of the
<head>
section. This will redirect the page automatically.
Read : http://nodejs.org/docs/v0.4.12/api/http.html#response.setHeader One other way is to use meta redirect. print this as part of the
<head>
section. This will redirect the page automatically.
<meta http-equiv="Refresh" content="0; url=http://your_redirection_url" />
像这样
window.location.replace("http://www.website.com/student.html");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.