我有一个jsp页面,它打开一个html页面并传递一些隐藏的参数。如下......
<form name="DMSForm" method="post" action="<bean:write name="URL"/>" >
<input type="hidden" name="userName" value="<bean:write name="userName"/>">
<input type="hidden" name="password" value="<bean:write name="password"/>">
HTML页面有很多其他代码,除了它调用一个url,它需要发送从JSP接收的这些userName和密码。如下......
<frame longdesc="/styles/blank.htm" name="topFrame" id="topFrame" src="**/servlets/servlets.CH_Vault?INT=1&Name=UserNameFromJSP;&Password=passwordFromJSP;**" border="0" frameborder="no" noresize scrolling="no"/>
如何在html中访问JSP传递的userName和密码?
答案 0 :(得分:0)
不幸的是,HTML和JavaScript无法处理给定的URL参数。
你可以用一点JavaScript来做到这一点
function gup( name, url ) {
// If you don't specify an URL in the parameters, it will take the current URL of the browser
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
return results == null ? null : results[1];
}
var testUrl = "www.test.com/t.html?a=1&b=3&promo=m2-m3-m4-m5"
var promo_param = gup('promo', 'test') // returns "m2-m3-m4-m5"