【问题标题】:org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user'org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'java.lang.String'没有属性'user'
【发布时间】:2019-03-07 04:13:25
【问题描述】:

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

**错误堆栈跟踪是**

ERROR [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(Unknown Source) 引起: 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;
    }

}

【问题讨论】:

  • 也发布您的model 课程
  • 按要求发布了我的模型类@Swati
  • 你的 User 类是否是公共的,并且也是 getter setter?
  • 是的用户类是公共的,它也有所有字段的getter setter @Swati
  • 试试 ${user.firstname} 不要使用 registerModel 看看它是否打印了一些东西,因为我没有在您的代码中发现任何错误,也许this 会帮助您。

标签: java xml spring jsp spring-webflow


【解决方案1】:

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

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

您将字符串值“registerHandler.init()”放入flowScope.registerModel,而不是调用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">

(另外,通过声明&lt;var&gt;s“用户”和“计费”,它们会自动置于流范围内,因此您可以直接在JSP中引用它们,如${user.firstname}。)

【讨论】:

    猜你喜欢
    • 2018-01-20
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2016-10-01
    • 2015-03-12
    • 2015-07-29
    相关资源
    最近更新 更多