Spring Webflow:尝试添加新视图时接收空指针异常

时间:2014-05-12 19:55:29

标签: spring jsp java-ee cas

以下是我希望引用registerViewTwo.jsp

的视图
<%@page import="java.util.Calendar"%>
<%@page import="net.tanesha.recaptcha.ReCaptcha"%>
<%@page import="net.tanesha.recaptcha.ReCaptchaFactory"%>
<%@page import="com.ewusu.util.Props"%>
<head>
    <title>Register</title>
</head>

<jsp:directive.include file="includes/top.jsp" />
<form:form method="post" id="fm1" cssClass="fm-v clearfix" commandName="${commandName}" htmlEscape="true">

<table style="padding-top: 10px; padding-bottom: 20px;"> 
    <tr><td>First Name:</td><td>    <form:input cssClass="required" cssErrorClass="error" id="firstname" size="50" 
        path="firstname" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="firstname" cssClass="errors" /></td> </tr> 
    <tr> <td>Last Name:</td> <td><form:input cssClass="required" cssErrorClass="error" id="lastname" size="50" 
        path="lastname" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="lastname" cssClass="errors" /></td> </tr>
    <tr> <td>Email:</td> <td><form:input cssClass="required" cssErrorClass="error" id="emailaddress" size="50" 
        path="emailaddress" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="emailaddress" cssClass="errors" /></td> </tr>
    <tr> <td>Password:</td> <td><form:password cssClass="required" cssErrorClass="error" id="password" size="50" 
        path="password" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="password" cssClass="errors" /></td> </tr>

    <tr> <td>Gender:</td> 
    <td><form:select path="gender">
        <form:option value="NONE" label="- Select Gender -"/>
        <form:option value="Male" label="Male"/>
        <form:option value="Female" label="Female"/>
    </form:select></td>
     <td><form:errors path="gender" cssClass="errors" /></td> </tr>

    <tr> <td>Birthday:</td>
        <td><form:select path="day">
            <form:option value="0" label="- Day: -"/>
            <% for(int i = 1; i <= 31; i++) { %>
                <form:option value="<%=i %>" label="<%=String.valueOf(i) %>"/>
            <% }%> 
        </form:select>
        <form:select path="month">
            <form:option value="0" label="- Month: -"/>
                <% 
                    String[] months = new String[] {
                        "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
                    };

                    for(int i = 0; i < months.length; i++) {

                %>  
                    <form:option value="<%=i+1 %>" label="<%=months[i] %>"/>
                <% } %>
        </form:select>
        <form:select path="year">
            <form:option value="0" label="- Year: -"/>
            <% 
                int year = Calendar.getInstance().get(Calendar.YEAR) - 5;//seriously how many 5 yrs olds use the net?!?
                int minYear = year - 90; //sure 80 year olds have better things to do with their time
                for(; year >= minYear; year--) {
            %>      
                <form:option value="<%=year %>" label="<%=String.valueOf(year) %>"/>
            <% } %>
        </form:select></td> 
        <td><form:errors path="day" cssClass="errors" /></td>
    </tr>

    <tr> <td>Remember me:</td>
        <td><form:checkbox path="rememberLogin" value="1"/></td>
        <td><form:errors path="rememberLogin" cssClass="errors" /></td>
    </tr> 
</table>

<%
   ReCaptcha c = ReCaptchaFactory.newReCaptcha(Props.PUBLIC_RECAPTCHA_KEY, Props.PRIVATE_RECAPTCHA_KEY, false);
   out.print(c.createRecaptchaHtml(null, null));
%>          
    <form:errors path="recaptcha" cssClass="errors"/>
<div> 
    <span style="padding-right: 10"> <input class="btn-submit" type="submit" name="_eventId_submit" value="submit" /> </span> 
    <span> <input class="btn-submit" type="submit" name="_eventId_cancel" value="cancel"/> </span> 
</div>  

    <input type="hidden" name="lt" value="${flowExecutionKey}" />

</form:form>

<jsp:directive.include file="includes/bottom.jsp" />

这是web.xml文件cas servlet mapping

    **<servlet-mapping>
        <servlet-name>cas</servlet-name>
        <url-pattern>/register</url-pattern>
    </servlet-mapping>

    <!--  Added reguser servlet mapping 4th May 2014 -->

    <servlet-mapping>
        <servlet-name>cas</servlet-name>
        <url-pattern>/reguser</url-pattern>
    </servlet-mapping>**

    <!-- Section removed to fit Stackoverflow -->

    <session-config>
        <!-- Default to 5 minute session timeouts -->
        <session-timeout>5</session-timeout>
    </session-config>

以下是我的cas-servlet.xml文件的一个片段,它将url reguser映射到webflow registertwo-webflow.xml

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"
        p:flowExecutor-ref="flowExecutor"
        p:flowUrlHandler-ref="flowUrlHandler" />

    <bean id="flowUrlHandler" class="org.jasig.cas.web.flow.CasDefaultFlowUrlHandler" />

    <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
        <webflow:flow-execution-attributes>
            <webflow:always-redirect-on-pause value="false" />
        </webflow:flow-execution-attributes>
    </webflow:flow-executor>

    <webflow:flow-registry id="flowRegistry" flow-builder-services="builder">
        <webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
        <webflow:flow-location path="/WEB-INF/remind-webflow.xml" id="remind" />
        <webflow:flow-location path="/WEB-INF/register-webflow.xml" id="register" />
        <!--  Added new register for Customer and Spec 4th May 2014 -->
        **<webflow:flow-location path="/WEB-INF/registertwo-webflow.xml" id="reguser" />**
        <webflow:flow-location path="/WEB-INF/update-webflow.xml" id="update" />
    </webflow:flow-registry>

这是我的webflow xml文件registertwo-webflow.xml,我试图在此文件中显示的倒数第二行调用registerViewTwo.jsp。

<?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-2.0.xsd">

    <on-start>
        <evaluate expression="initialFlowSetupAction" />
    </on-start>

    <!-- VIEW STATES -->
    <view-state id="register" view="registerViewTwo" model="customer">
    <!-- <var name="customer" class="com.ewusu.model.Customer"/>  -->

我试图在registertwo-webflow寄存器状态中调用registerTwoView.jsp,但是当我启动Tomcat webserver并尝试访问相关的URL时,我收到一个空指针异常(见下文)

SEVERE: Servlet.service() for servlet [cas] in context with path [/sso] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'register' of flow 'reguser'] with root cause
java.lang.NullPointerException
    at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:50)
    at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:180)
    at org.springframework.webflow.engine.ViewState.render(ViewState.java:314)
    at org.springframework.webflow.engine.ViewState.doEnter(ViewState.java:208)
    at org.springframework.webflow.engine.State.enter(State.java:194)
    at org.springframework.webflow.engine.Flow.start(Flow.java:535)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:364)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start

奇怪的是,可以使用registertwo-webflow.xml文件访问现有的registerView.jsp。我希望我提供了足够的信息,因为我无法理解什么是错误的

0 个答案:

没有答案