org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'java.lang.String'不具有属性'user'

时间:2019-03-07 04:13:25

标签: java xml spring jsp spring-webflow

我正在使用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"%>

我的signup-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>

**错误堆栈跟踪为**

  

错误[io.undertow.request](默认任务5)UT005023:异常   处理要求   /OnlineShoppingFE/views/flows/register/signup-confirm.jsp:   org.springframework.web.util.NestedServletException:请求   处理失败;嵌套异常为   org.springframework.webflow.execution.FlowExecutionException:   在流“注册”的状态“确认”时抛出异常   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:687)处   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)处   io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)     在   io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)     在   io.undertow.servlet.handlers.ServletChain $ 1.handleRequest(ServletChain.java:68)     在   io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)     在   org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)     在   io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)     在   io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)     在   io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)     在   io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)     在   io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)     在   io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 100(ServletInitialHandler.java:81)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 2.call(ServletInitialHandler.java:138)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 2.call(ServletInitialHandler.java:135)     在   io.undertow.servlet.core.ServletRequestContextThreadSetupAction $ 1.call(ServletRequestContextThreadSetupAction.java:48)     在   io.undertow.servlet.core.ContextClassLoaderSetupAction $ 1.call(ContextClassLoaderSetupAction.java:43)     在   org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda $ create $ 0(SecurityContextThreadSetupAction.java:105)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1514)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:81)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:104)     在   io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)     在   io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:830)     在   org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)     在   org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)     在   org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)     在   org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.run(EnhancedQueueExecutor.java:1378)     在java.lang.Thread.run(未知源)造成原因:   org.springframework.webflow.execution.FlowExecutionException:   在流“注册”的状态“确认”时抛出异常   org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:573)     在   org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)     在   org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)     在   org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:253)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)     ... 45更多原因:java.lang.IllegalStateException:异常   发生渲染视图org.springframework.web.servlet.view.JstlView:   名称为“流程/注册/注册确认”;网址   [/views/flows/register/signup-confirm.jsp]位于   org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:200)     在   org.springframework.webflow.engine.ViewState.render(ViewState.java:293)     在   org.springframework.webflow.engine.ViewState.refresh(ViewState.java:242)     在   org.springframework.webflow.engine.ViewState.resume(ViewState.java:220)     在org.springframework.webflow.engine.Flow.resume(Flow.java:537)处   org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)     ... 50更多原因:org.apache.jasper.JasperException:   javax.el.PropertyNotFoundException:类'java.lang.String'确实   没有属性“用户”。在   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:473)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)处   io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)     在   io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)     在   io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)     在   io.undertow.servlet.handlers.ServletChain $ 1.handleRequest(ServletChain.java:68)     在   io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:274)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:209)     在   io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:221)     在   io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:147)     在   io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111)     在   org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)     在   org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)     在   org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:55)     在   org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:196)     ... 55更多原因:javax.el.PropertyNotFoundException:该类   'java.lang.String'没有属性'user'。在   javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:568)在   javax.el.BeanELResolver.getValue(BeanELResolver.java:229)在   org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)     在com.sun.el.parser.AstValue.getValue(AstValue.java:139)处   com.sun.el.parser.AstValue.getValue(AstValue.java:203)在   com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)     在   org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:917)     在   org.apache.jsp.views.flows.register.signup_002dconfirm_jsp._jspService(signup_002dconfirm_jsp.java:230)     在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)处   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)     ...还有75个

RegisterModel类是

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类

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;
    }

}

1 个答案:

答案 0 :(得分:1)

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

<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'">

这也不应在“帐单”两边加上单引号:

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

(此外,通过声明<var>的“用户”和“账单”,它们将自动置于流范围内,因此您可以像${user.firstname}一样直接在JSP中引用它们。)