java - 发送从客户端网站登录到服务提供商网站的发布请求

标签 java javascript spring jsp

客户端网站(asp.net)有触发onclick事件的图标。 提供商网站(java) 单击时,

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

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

问题是,在 spring 3 中,登录提交不允许 get 请求(我认为)..

使用以下 JavaScript 进行发布,但出现了 CSRF token 问题。

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;
}

最佳答案

那么你不应该在打开的新窗口中设置 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>

关于java - 发送从客户端网站登录到服务提供商网站的发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16674300/

相关文章:

java - Apache shiro 和 JSESSIONID

java - Mockito 和 JUnit : Which is the best to use Runner or TestRule?

javascript - 在不丢失 'this' 上下文的情况下将原型(prototype)函数作为参数传递

javascript - 包含 jquery-mobile.js 链接后不再重定向

java - 使用 SimpleTable 数据填充 JCombobox

java - EJB bean 和 CDI bean 以及注入(inject)

javascript - D3 用不同的数据创建相同的图像

java - 在 Spring 中排除单元测试 @Configurations 的最佳方法?

java - spring 内部是否使用 servlet?

java - Spring:自动创建年月属性值?