revised JSP-based views to never fail when trying to setting forward attributes (SPR-6623)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2755 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
95015712fc
commit
41e9b66cda
|
|
@ -20,7 +20,6 @@ import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
@ -70,7 +69,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
|
||||||
|
|
||||||
private boolean alwaysInclude = false;
|
private boolean alwaysInclude = false;
|
||||||
|
|
||||||
private Boolean exposeForwardAttributes;
|
private volatile Boolean exposeForwardAttributes;
|
||||||
|
|
||||||
private boolean exposeContextBeansAsAttributes = false;
|
private boolean exposeContextBeansAsAttributes = false;
|
||||||
|
|
||||||
|
|
@ -181,7 +180,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether we need explictly expose the Servlet 2.4 request attributes
|
* Checks whether we need to explicitly expose the Servlet 2.4 request attributes
|
||||||
* by default.
|
* by default.
|
||||||
* @see #setExposeForwardAttributes
|
* @see #setExposeForwardAttributes
|
||||||
* @see #exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest)
|
* @see #exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest)
|
||||||
|
|
@ -330,7 +329,13 @@ public class InternalResourceView extends AbstractUrlBasedView {
|
||||||
*/
|
*/
|
||||||
protected void exposeForwardRequestAttributes(HttpServletRequest request) {
|
protected void exposeForwardRequestAttributes(HttpServletRequest request) {
|
||||||
if (this.exposeForwardAttributes != null && this.exposeForwardAttributes) {
|
if (this.exposeForwardAttributes != null && this.exposeForwardAttributes) {
|
||||||
WebUtils.exposeForwardRequestAttributes(request);
|
try {
|
||||||
|
WebUtils.exposeForwardRequestAttributes(request);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
// Servlet container rejected to set internal attributes, e.g. on TriFork.
|
||||||
|
this.exposeForwardAttributes = Boolean.FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,25 @@ import org.springframework.web.util.WebUtils;
|
||||||
*/
|
*/
|
||||||
public class TilesView extends AbstractUrlBasedView {
|
public class TilesView extends AbstractUrlBasedView {
|
||||||
|
|
||||||
|
private volatile boolean exposeForwardAttributes = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether we need to explicitly expose the Servlet 2.4 request attributes
|
||||||
|
* by default.
|
||||||
|
* <p>This will be done by default on Servlet containers up until 2.4, and skipped
|
||||||
|
* for Servlet 2.5 and above. Note that Servlet containers at 2.4 level and above
|
||||||
|
* should expose those attributes automatically! This feature exists for
|
||||||
|
* Servlet 2.3 containers and misbehaving 2.4 containers only.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void initServletContext(ServletContext sc) {
|
||||||
|
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
|
||||||
|
this.exposeForwardAttributes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkResource(final Locale locale) throws Exception {
|
public boolean checkResource(final Locale locale) throws Exception {
|
||||||
TilesContainer container = ServletUtil.getContainer(getServletContext());
|
TilesContainer container = ServletUtil.getContainer(getServletContext());
|
||||||
|
|
@ -91,9 +110,14 @@ public class TilesView extends AbstractUrlBasedView {
|
||||||
// Tiles is going to use a forward, but some web containers (e.g. OC4J 10.1.3)
|
// Tiles is going to use a forward, but some web containers (e.g. OC4J 10.1.3)
|
||||||
// do not properly expose the Servlet 2.4 forward request attributes... However,
|
// do not properly expose the Servlet 2.4 forward request attributes... However,
|
||||||
// must not do this on Servlet 2.5 or above, mainly for GlassFish compatibility.
|
// must not do this on Servlet 2.5 or above, mainly for GlassFish compatibility.
|
||||||
ServletContext sc = getServletContext();
|
if (this.exposeForwardAttributes) {
|
||||||
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
|
try {
|
||||||
WebUtils.exposeForwardRequestAttributes(request);
|
WebUtils.exposeForwardRequestAttributes(request);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
// Servlet container rejected to set internal attributes, e.g. on TriFork.
|
||||||
|
this.exposeForwardAttributes = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue