Struts2 个属性未在 JSP 中填充
Struts2 properties not populated in JSP
我有一个 Struts 2.5.10.1 应用程序,它没有填充任何 EL 或 OGNL 变量。我已经用调试器验证了变量是在操作 class 上设置的。错误是“class 'com.sun.proxy.$Proxy404' 没有 属性 'jobRunning'。
文件:javax/el/BeanELResolver.java
行号:686"。这是 Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="global"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="namedVariable"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.multipart.maxSize" value="16777216"/>
<constant name="struts.convention.default.parent.package" value="parent-package"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/>
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>
<package name="parent-package" extends="security-manager,struts2-support,json-default" namespace="/">
</package>
</struts>
该操作具有这些基于注释的拦截器:
@InterceptorRefs({
@InterceptorRef(value = "exception"),
@InterceptorRef(value = "alias"),
@InterceptorRef(value = "servletConfig"),
@InterceptorRef(value = "i18n"),
@InterceptorRef(value = "userInfoObjectInterceptor"),
@InterceptorRef(value = "securityCheckInterceptor", params = {"mode", "before"}),
@InterceptorRef(value = "prepare"),
@InterceptorRef(value = "debugging"),
@InterceptorRef(value = "fileUpload"),
@InterceptorRef(value = "checkbox"),
@InterceptorRef(value = "multiselect"),
@InterceptorRef(value = "staticParams"),
@InterceptorRef(value = "actionMappingParams"),
@InterceptorRef(value = "params", params = {"excludeParams", "dojo\..*,^struts\..*", "ordered", "true"}),
@InterceptorRef(value = "securityCheckInterceptor", params = {"mode", "after"}),
@InterceptorRef(value = "validation", params = {"validateAnnotatedMethodOnly", "true"}),
@InterceptorRef(value = "workflow")
})
jsp header:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="app" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/dateFormat.js"></script>
<%--@elvariable id="action" type="njob.actions.WelcomeAction"--%>
<app:wrapper pageTitle="Welcome Page">
<jsp:body>
失败点:
<c:out value="${action.currentEnvironment}"/> <%-- also fails with <s:property value="%{currentEnvironment}--%>
操作 class 具有正确的 getter 和设置器:
public String getCurrentEnvironment() {
return currentEnvironment;
}
public void setCurrentEnvironment(String currentEnvironment) {
this.currentEnvironment = currentEnvironment;
}
好的,我找到了如何强制创建基于 CGLIB 的操作代理。我将此行添加到 applicationContext.xml:
<aop:aspectj-autoproxy proxy-target-class="true"/>
我仍然不知道为什么 Struts 使用了错误的代理 class。我的应用程序甚至没有使用 Spring AOP 库。我认为这与我公司的自定义 struts 插件有关。
我有一个 Struts 2.5.10.1 应用程序,它没有填充任何 EL 或 OGNL 变量。我已经用调试器验证了变量是在操作 class 上设置的。错误是“class 'com.sun.proxy.$Proxy404' 没有 属性 'jobRunning'。 文件:javax/el/BeanELResolver.java 行号:686"。这是 Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="global"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="namedVariable"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.multipart.maxSize" value="16777216"/>
<constant name="struts.convention.default.parent.package" value="parent-package"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/>
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>
<package name="parent-package" extends="security-manager,struts2-support,json-default" namespace="/">
</package>
</struts>
该操作具有这些基于注释的拦截器:
@InterceptorRefs({
@InterceptorRef(value = "exception"),
@InterceptorRef(value = "alias"),
@InterceptorRef(value = "servletConfig"),
@InterceptorRef(value = "i18n"),
@InterceptorRef(value = "userInfoObjectInterceptor"),
@InterceptorRef(value = "securityCheckInterceptor", params = {"mode", "before"}),
@InterceptorRef(value = "prepare"),
@InterceptorRef(value = "debugging"),
@InterceptorRef(value = "fileUpload"),
@InterceptorRef(value = "checkbox"),
@InterceptorRef(value = "multiselect"),
@InterceptorRef(value = "staticParams"),
@InterceptorRef(value = "actionMappingParams"),
@InterceptorRef(value = "params", params = {"excludeParams", "dojo\..*,^struts\..*", "ordered", "true"}),
@InterceptorRef(value = "securityCheckInterceptor", params = {"mode", "after"}),
@InterceptorRef(value = "validation", params = {"validateAnnotatedMethodOnly", "true"}),
@InterceptorRef(value = "workflow")
})
jsp header:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="app" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/dateFormat.js"></script>
<%--@elvariable id="action" type="njob.actions.WelcomeAction"--%>
<app:wrapper pageTitle="Welcome Page">
<jsp:body>
失败点:
<c:out value="${action.currentEnvironment}"/> <%-- also fails with <s:property value="%{currentEnvironment}--%>
操作 class 具有正确的 getter 和设置器:
public String getCurrentEnvironment() {
return currentEnvironment;
}
public void setCurrentEnvironment(String currentEnvironment) {
this.currentEnvironment = currentEnvironment;
}
好的,我找到了如何强制创建基于 CGLIB 的操作代理。我将此行添加到 applicationContext.xml:
<aop:aspectj-autoproxy proxy-target-class="true"/>
我仍然不知道为什么 Struts 使用了错误的代理 class。我的应用程序甚至没有使用 Spring AOP 库。我认为这与我公司的自定义 struts 插件有关。