org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: class 'java.lang.String' 没有 属性 'user'

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user'

我正在使用 spring webflow
我的 jsp 页面是

<!-- header -->
<%@include file="../shared/flows-header.jsp"%>

<div class = "container">


<div class = "row">

<div class = col-sm-6>

    <div class = "panel panel-primary">

        <div class = "panel-heading">

            <h4>Personal Details</h4>

        </div>

        <div class = "panel-body">

            <!-- to display personal details -->
                    <div class="text-center">
                        <h3>Name : <strong>${registerModel.user.firstname} ${registerModel.user.lastname}</strong></h3>
                        <h4>Email : <strong>${registerModel.user.email}</strong></h4>
                        <h4>Contact : <strong>${registerModel.user.contactNumber}</strong></h4>
                        <h4>Role : <strong>${registerModel.user.role}</strong></h4>

                    </div>

                    <!-- anchor tag to move to personal details page to edit -->
                    <p>
                        <a href = "${flowExecutionUrl}&_eventId_personal" class = "btn btn-primary">Edit</a>        
                    </p>
        </div>

    </div>

</div>


<div class = col-sm-6>

    <div class = "panel panel-primary">

        <div class = "panel-heading">

            <h4>Billing Address</h4>

        </div>

        <div class = "panel-body">

            <!-- to display billing address -->
                    <div class="text-center">
                        <p>${registerModel.billing.addressLineOne}, </p>
                        <p>${registerModel.billing.addressLineTwo}, </p>
                        <p>${registerModel.billing.city} -  ${registerModel.billing.postalCode}, </p>
                        <p>${registerModel.billing.state}</p>
                        <p>${registerModel.billing.country}</p>
                    </div>      

            <!-- anchor tag to move to billing address page to edit -->
            <p>
                <a href = "${flowExecutionUrl}&_eventId_billing" class = "btn btn-primary">Edit</a>
            </p>

        </div>

    </div>

</div>

<div class = "row">

    <div class = "col-sm-4 col-sm-offset-4">

        <div class = "text-center">

            <!-- anchor tag to move to success page -->
            <a href = "${flowExecutionUrl}&_eventId_submit" class = "btn btn-primary">Confirm Submission</a>

        </div>

    </div>

</div>

</div>

</div>

<!-- footer -->
<%@include file="../shared/flows-footer.jsp"%>

我的注册-flow.xml页面是

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow.xsd">

    <var  name = "user" class = "model.entity.User" />
    <var  name = "billing" class = "model.entity.Address" />

    <on-start>
        <evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />
    </on-start>


    <!-- start state -->
    <view-state id = "personal" view = "flows/register/signup-personal" model = "'user'"><!-- model value is used as modelAttribute in spring form -->
        <transition on = "billing" to = "billing" /><!-- to billing view state -->
        <on-exit>
            <evaluate expression="'registerHandler.addUser(flowScope.registerModel , user)'" />
        </on-exit>
     </view-state>

    <view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">
        <transition on = "personal" to = "personal" />
        <transition on = "confirm" to = "confirm" />
        <on-exit>
            <evaluate expression="'registerHandler.addBilling(flowScope.registerModel , billing)'" />
        </on-exit>
     </view-state>

    <view-state id = "confirm" view = "flows/register/signup-confirm" model = "flowScope.registerModel">
        <transition on = "personal" to = "personal" />
        <transition on = "billing" to = "billing" />
        <transition on = "submit" to = "submit" />  
     </view-state>

    <action-state id="submit">
        <evaluate expression="'registerHandler.saveAll(flowScope.registerModel)'" />
        <transition on = "success" to = "success" />
    </action-state>

    <!-- end state -->
    <end-state id = "home" view = "externalRedirect:contextRelative:/" />
    <end-state id = "success" view = "flows/register/signup-success" />


    <!-- global transition -->
    <global-transitions>
        <transition on = "home" to = "home"/>
    </global-transitions>

</flow>

**错误堆栈跟踪是**

ERROR [io.undertow.request] (default task-5) UT005023: Exception handling request to /OnlineShoppingFE/views/flows/register/signup-confirm.jsp: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'confirm' of flow 'register' at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292) at io.undertow.servlet.handlers.ServletInitialHandler.access0(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler.call(ServletInitialHandler.java:138) at io.undertow.servlet.handlers.ServletInitialHandler.call(ServletInitialHandler.java:135) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create[=20=](SecurityContextThreadSetupAction.java:105) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create[=20=](UndertowDeploymentInfoService.java:1514) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create[=20=](UndertowDeploymentInfoService.java:1514) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create[=20=](UndertowDeploymentInfoService.java:1514) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create[=20=](UndertowDeploymentInfoService.java:1514) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272) at io.undertow.servlet.handlers.ServletInitialHandler.access[=20=]0(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:104) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360) at io.undertow.server.HttpServerExchange.run(HttpServerExchange.java:830) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378) at java.lang.Thread.run(Unknown Source) Caused by: org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'confirm' of flow 'register' at org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:573) at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263) at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169) at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:253) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) ... 45 more Caused by: java.lang.IllegalStateException: Exception occurred rendering view org.springframework.web.servlet.view.JstlView: name 'flows/register/signup-confirm'; URL [/views/flows/register/signup-confirm.jsp] at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:200) at org.springframework.webflow.engine.ViewState.render(ViewState.java:293) at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:242) at org.springframework.webflow.engine.ViewState.resume(ViewState.java:220) at org.springframework.webflow.engine.Flow.resume(Flow.java:537) at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259) ... 50 more Caused by: org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user'. at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:473) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32) at io.undertow.servlet.handlers.ServletChain.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:274) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:209) at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:221) at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:147) at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:55) at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:196) ... 55 more Caused by: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user'. at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:568) at javax.el.BeanELResolver.getValue(BeanELResolver.java:229) at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110) at com.sun.el.parser.AstValue.getValue(AstValue.java:139) at com.sun.el.parser.AstValue.getValue(AstValue.java:203) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:917) at org.apache.jsp.views.flows.register.signup_002dconfirm_jsp._jspService(signup_002dconfirm_jsp.java:230) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433) ... 75 more

RegisterModel class 是

package flow.model;

import java.io.Serializable;

import model.entity.Address;
import model.entity.User;

public class RegisterModel implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private User user;

    private Address billing;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Address getBilling() {
        return billing;
    }

    public void setBilling(Address billing) {
        this.billing = billing;
    }


}

RegisterHandler class

package handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import flow.model.RegisterModel;
import model.dao.IUserDAO;
import model.entity.Address;
import model.entity.Cart;
import model.entity.User;

@Component
public class RegisterHandler {

    @Autowired
    private IUserDAO userDAO;

    public RegisterModel init()
    {
        System.out.println(new RegisterModel().toString());
        return (new RegisterModel());
    }

    public void addUser(RegisterModel registerModel,User user)
    {
        registerModel.setUser(user);
    }

    public void addBilling(RegisterModel registerModel,Address billing)
    {
        registerModel.setBilling(billing);
    }

    public String saveAll(RegisterModel model)
    {
        String transitionValue = "success";

        //fetch user
        User user = model.getUser();

        if(user.getRole().equals("ROLE"))
        {
            Cart cart = new Cart();
            cart.setUser(user);
            user.setCart(cart);
        }

        //save user
        userDAO.addUser(user);

        //get address
        Address billing = model.getBilling();   
        billing.setUserId(user.getId());
        billing.setBilling(true);

        //save the address
        userDAO.addAddress(billing);

        return transitionValue;
    }

}

我看到了一些可能的误解,但我认为最主要的是您在不应该的属性周围使用了单引号。导致此特定问题的原因是:

<evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />

您正在向 flowScope.registerModel 中输入字符串值 "registerHandler.init()",而不是调用 registerHandler.init().

的结果

而是像这样删除单引号:

<evaluate expression="registerHandler.init()" result = "flowScope.registerModel" />

后面的参考文献也一样:

   <view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">

这也不应该在 "billing":

周围有单引号
   <view-state id = "billing" view = "flows/register/signup-billing" model = "billing">

(另外,通过声明 <var>s "user" 和 "billing",它们会自动放在流程范围内,因此您可以在 JSP 中直接引用它们,如 ${user.firstname}.)