[英]SendRedirect not working from JSP Scriptlet
I have a main.jsp.我有一个 main.jsp。
Onclick
on a button in main.jsp, I am launching my JSP scriptlet in another window. Onclick
在main.jsp中的按钮,我发动在另一个窗口我的JSP脚本。 In the JSP Scriptlet, I am processing URL parameters and constructing the URL.在 JSP Scriptlet 中,我正在处理 URL 参数并构建 URL。 URL construction works fine;
URL 构建工作正常; I print it in the log file and manually open the link constructed.
我将其打印在日志文件中并手动打开构建的链接。
I want to redirect this JSP scriptlet page to the new URL constructed (different domain), in order to send redirect.我想将此 JSP 脚本页面重定向到构造的新 URL(不同域),以便发送重定向。
I am putting this line at the end after constructing the URL.构建 URL 后,我将此行放在末尾。
response.sendRedirect(url);
When I try to sendRedirect
nothing happens.当我尝试
sendRedirect
没有任何反应。 Can anyone please help me figure out what's wrong?任何人都可以帮我弄清楚出了什么问题吗?
To call the JavaScript in this scriplet use要在此脚本中调用 JavaScript,请使用
url = urlBuffer.toString();
System.out.println("url from JS server="+url);
%>
<script type="text/javascript">
window.location=<%=url%>
</script>
Onclick - is postback or callback event? Onclick - 是回发还是回调事件? Do you use ajax?
你用ajax吗? When you using ajax request, you can add code to success event:
document.location='some url';
使用ajax请求时,可以在success事件中添加代码:
document.location='some url';
When postback - document.location='<%= url%>';
回发时 -
document.location='<%= url%>';
window.location= .. didn't work for me. window.location= .. 对我不起作用。
I did this and it worked我这样做了,它奏效了
<script>
window.location.href = "<%= url %>";
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.