revised JSP-based views to never fail when trying to setting forward attributes (SPR-6623)
This commit is contained in:
parent
4931e8b229
commit
a7a03356f4
|
|
@ -20,7 +20,6 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
|
@ -70,7 +69,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
|
|||
|
||||
private boolean alwaysInclude = false;
|
||||
|
||||
private Boolean exposeForwardAttributes;
|
||||
private volatile Boolean exposeForwardAttributes;
|
||||
|
||||
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.
|
||||
* @see #setExposeForwardAttributes
|
||||
* @see #exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest)
|
||||
|
|
@ -330,7 +329,13 @@ public class InternalResourceView extends AbstractUrlBasedView {
|
|||
*/
|
||||
protected void exposeForwardRequestAttributes(HttpServletRequest request) {
|
||||
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 {
|
||||
|
||||
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
|
||||
public boolean checkResource(final Locale locale) throws Exception {
|
||||
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)
|
||||
// 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.
|
||||
ServletContext sc = getServletContext();
|
||||
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
|
||||
WebUtils.exposeForwardRequestAttributes(request);
|
||||
if (this.exposeForwardAttributes) {
|
||||
try {
|
||||
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