再struts-config.xml文件的forward下有个redirect属性,这个属性的值为true和false有什么区别呢
redirect="true"时,会调用sendRedirect进行定向,而sendRedirect定向采用的时"(HTTP status 302)。
再浏 览器发生页面改变
redirect="false"时采用的是server-side forward端的定向
public void sendRedirect(String location)
throws IOException {
if (isCommitted())
throw new IllegalStateException
(sm.getString("coyoteResponse.sendRedirect.ise"));
// Ignore any call from an included servlet
if (included)
return;
// Clear any data content that has been buffered
resetBuffer();
// Generate a temporary redirect to the specified location
try {
String absolute = toAbsolute(location);
// public static final int SC_FOUND = 302;
setStatus(SC_FOUND);
setHeader("Location", absolute);
} catch (IllegalArgumentException e) {
setStatus(SC_NOT_FOUND);
}
引起的结果是:
如果采用redirect=true,那么request是传寄不再下一个页面, 而false是可以
本文详细解析了Struts框架中配置文件forward元素的redirect属性的作用。当该属性设置为true时,会触发HTTP 302重定向,导致浏览器地址栏显示新的URL,并且Request对象不会被传递到目标页面;而设置为false时,则采用服务器端内部转发,Request对象得以保留。
1047

被折叠的 条评论
为什么被折叠?



