gpt4 book ai didi

javascript - Java - SendRedirect 不从对话框重定向

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:52 25 4
gpt4 key购买 nike

我有一个引导表单,通过单击 createTicketButton 按钮提交,它执行 jquery 调用

$('#createTicketButton').click(function(event) 
{
$.ajax({
processData : false,
contentType : 'application/json',
url : 'myUrl',
"accept" : 'json',
"dataType" : 'json',
"type" : "POST",
data : JSON.stringify(data),
success : function(response)
{}
});
});

最后,它传递给过滤器以确保 CSFR token 已传递并与服务器中存在的内容匹配

如果 token 不匹配,它应该重定向到登录页面这是问题重定向导致 500 错误(内部服务器错误)并且不重定向并且弹出窗口仍然显示任何帮助?

public class CsrfFilter implements Filter
{
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
boolean validToken = realToken.equals(requestToken);
if (validToken)
{
chain.doFilter(request, response);
return;
}
else
{
UriBuilder redirectUri = UriBuilder.fromUri("/login");
try
{
String returnUrl = new URI(req.getHeader("referer")).getPath();
redirectUri.queryParam("r", returnUrl);
}
catch (URISyntaxException | NullPointerException e)
{
// We don't need a return URL
}
res.sendRedirect(redirectUri.build().toString());
}
}
}

我的 HTML

    <th:block th:fragment="createTicketFormModal">
<div id="createNewTicket" class="modal fade" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" aria-hidden="true" data-modal-index="1">
<div class="modal-dialog">
<div class="modal-content">
<div class="create-header modal-header">
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 id="edit-admin-modal" class="modal-title create-title">Create Ticket</h4>
</div>
<div class="modal-body">
<form id="create-ticket-form" class="create-form" method="POST" action="/cats/tickets/new">
<div class="alert alert-danger form-errors collapse"></div>

<!-- The form buttons -->
<input id="createTicketButton" class="btn btn-primary btn-block catsSubmit" type="button" value="Create Ticket" />
<button id="createTicketFormClearButton" class="btn btn-info btn-block" type="button">Clear</button>
<button class="btn btn-default btn-block" type="button" data-dismiss="modal">Close</button>
<input id="file-id" type="hidden" />

</form>
</div>
</div>
</div>
</div>

</th:block>

错误堆栈

java.lang.IllegalStateException: UT010019: Response already commited
io.undertow.servlet.spec.HttpServletResponseImpl.sendRedirect(HttpServletResponseImpl.java:173)
com.ephibian.j2ee.security.CsrfFilter.RedirectToLogin(CsrfFilter.java:194)

最佳答案

它看起来像是您的 servlet 中发生的异常。尝试使用调试器并在此处发布异常消息。

关于javascript - Java - SendRedirect 不从对话框重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57719574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com