如何在cgi-script(javascript)中读取浏览器的地址栏参数

时间:2017-12-04 22:57:25

标签: javascript node.js tomcat cgi-bin

我想获取浏览器地址栏的参数 http://localhost:8080/WebApplication3/cgi-bin/servlet.js?number1=1&number2=2 例如,从服务器返回“number1 = 1” 我使用Apache Tomchat 9.0.1,node.js 8.9.1,NetBeans 8.2。我配置了脚本Python http://localhost:8080/WebApplication2/cgi-bin/servlet.py?Number1=1,PHP,Java,一切运行良好 我的代码

console.log('Content-Type: text/html');
console.log('Access-Control-Allow-Origin: *');
console.log('');
console.log('qqqqqqqqqqqqqq');

//var urlParams = new URLSearchParams(window.location.search);//not work
//console.log(urlParams.toString());//not work
//console.log(window..protocol);//not work
//console.log('dfgsdfgs'+location.pathname.toString());//not work
//console.log(window.location.hash);//not work
//console.log(window.location.host);//not work
//if (window.location.search) {//not work
//    console.log('yes');//not work
//}else {//not work
//    console.log('no');//not work
//}    
//console.log(window.location.search.toString());//not work
//console.log(window.location.search);//not work

打开代码工作正常,给客户端“qqqqqqqqqqqqqq”,注释行不起作用

我要求不提供在节点中创建服务器,因为我想使用apache tomcat 我研究过node-сgi,我不明白如何使用它,建议使用文件.nd,.jss来修复.htaccess。真的没有这种类型的简单解决方案: $ _GET ['number1'];(php)或

form = cgi.FieldStorage ()
print int (form ["number1"]. value) + int (form ["number2"]. value)

在python中? 示例php

<?php header('Access-Control-Allow-Origin: *');
// put your code here
$num1 = $_GET['number1'];
$num2 = $_GET['number2'];
$sum = $num1 + $num2;
echo $sum;

示例python

import cgi
import cgitb
cgitb.enable()
print "Content-Type: text/html"     # HTML is following
print "Access-Control-Allow-Origin: *"
print                               # blank line, end of headers
form = cgi.FieldStorage()
print int(form["number1"].value) + int(form["number2"].value)

感谢您的帮助

0 个答案:

没有答案