发送邮件请求从客户端网站登录到服务提供商网站

时间:2013-05-21 15:54:04

标签: java javascript spring jsp

客户端网站(asp.net)具有触发onclick事件的图标。 提供者网站(java) 的onClick,

function goTourl(){
window.open(url)
}

url是这样的:https://example.org/j_spring_security_check?name=testing&pass=testing'

问题是,在春季3,登录提交不允许获取请求(我认为)..

使用以下javascript发布,但会出现CSRF令牌问题。

function openWindowWithPost(url,name,keys,values)
{
var newWindow = window.open(url, name); 
if (!newWindow) return false;
var html = "";
html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
if (keys && values && (keys.length == values.length))
for (var i=0; i < keys.length; i++)
html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
newWindow.document.write(html);
return newWindow;
}

1 个答案:

答案 0 :(得分:1)

那么你不应该在新窗口中设置url。

var newWindow = window.open(url, name);

应该是

var newWindow = window.open('', name);

您可以使用带有操作和目标集

的页面上的表单来避免整个弹出窗口
<form action="https://example.org/j_spring_security_check" method="post" target="_blank">
    <input type="hidden" name="foo" value="bar" />
</form>