简体   繁体   English

response.sendRedirect()没有正确重定向

[英]response.sendRedirect() doesn't redirect properly

I have a response.sendRedirect() in an if statement, linking to a link generated by string.format : 我在if语句中有一个response.sendRedirect() ,链接到string.format生成的链接:

String redirect = String.format("booking?order_id=%d&complete='0'&date='%s'&timePeriod='%s'&totalPrice=%d", intBookingID, date, timePeriod, intTotalPrice);

however this generates a 500 error instead or linking to the requested page, is this because I have used parameters, and If so how else would I do this? 但这会产生500错误或链接到请求的页面,这是因为我使用了参数,如果是这样,我怎么办呢?

它需要添加/your-web-context/ ahead所需的绝对地址

Http 500 code is Internal Server Error which means that something didn't go well in your server. Http 500代码是内部服务器错误 ,这意味着在您的服务器中出现问题。 I recommend you to check your logs and see what's happening. 我建议你查看你的日志,看看发生了什么。

What are you doing with the string redirect ? 你在用字符串redirect做什么? You should call HttpServletResponse.sendRedirect() but you must not call setStatus() , setContentType() , setContentLength() , setCharacterEncoding() , getOutputStream() or getWriter() on the HttpServletResponse before or after sendRedirect() as the API says: 你应该调用HttpServletResponse.sendRedirect()但是你不能sendRedirect()之前之后在HttpServletResponse上调用setStatus()setContentType()setContentLength()setCharacterEncoding()getOutputStream()getWriter() ,因为API说:

If the response has already been committed, this method throws an IllegalStateException. 如果响应已提交,则此方法将抛出IllegalStateException。

Is there any additional message in the 500 error page or in the log of the server? 500错误页面或服务器日志中是否还有其他消息? 500 (Internal Server Error) is typically an uncaught exception. 500(内部服务器错误)通常是未捕获的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM