responsesendRedirectstringBuildertoString;在重定向之前怎么给提示信息
在重定向之前给提示信息,可以通过在重定向之前将提示信息存储在session中,然后在重定向后的页面中读取并显示该提示信息。
示例代码:
// 在重定向之前给提示信息
String message = "提示信息";
request.getSession().setAttribute("message", message);
// 执行重定向
response.sendRedirect(stringBuilder.toString());
然后在重定向后的页面中,通过读取session中的提示信息,将其显示出来。
示例代码:
// 读取session中的提示信息
String message = (String) request.getSession().getAttribute("message");
// 显示提示信息
if (message != null) {
out.println("<div>" + message + "</div>");
}
// 清空session中的提示信息
request.getSession().removeAttribute("message");
这样就可以在重定向之前给出提示信息,并在重定向后的页面中显示该提示信息
原文地址: http://www.cveoy.top/t/topic/iU84 著作权归作者所有。请勿转载和采集!