Java 处理onSubmitation后引发异常
我对Spring非常陌生,我有一个simpleFormController,有两种方法。页面加载时调用referenceData with,提交表单时调用Submitation。在所有onsubmition代码完成之后,我得到了一个NullPointerException,我怀疑这与方法完成后控制流的去向有关。我希望在submitAction之后调用referenceData,以便页面的行为与首次加载时相同Java 处理onSubmitation后引发异常,java,spring,spring-mvc,Java,Spring,Spring Mvc,我对Spring非常陌生,我有一个simpleFormController,有两种方法。页面加载时调用referenceData with,提交表单时调用Submitation。在所有onsubmition代码完成之后,我得到了一个NullPointerException,我怀疑这与方法完成后控制流的去向有关。我希望在submitAction之后调用referenceData,以便页面的行为与首次加载时相同 <bean id="communicationsValidator" class=
<bean id="communicationsValidator" class="com.admin.portlet.communication.CommunicationsValidator"/>
<bean id="communicationsController" class="com.admin.portlet.communication.CommunicationsAdminController">
<property name="commandName" value="communications"/>
<property name="commandClass" value="com.admin.portlet.communication.vo.Communication"/>
<property name="formView" value="communications/communicationsAdmin"/>
<property name="successView" value="communications/communicationsAdmin"/>
<property name="validator"><ref bean="communicationsValidator"/></property>
<property name="dao"><ref bean="communicationsDao"/></property>
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1"/>
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="communicationsController"/></entry>
</map>
</property>
</bean>
我还有一个要求,可能会改变我上面的想法。我想根据onsubmition的结果传回一条成功或错误消息。最好的方法是什么。以下是我的代码的相关部分:
protected Map referenceData(PortletRequest arg0, Object arg1, Errors arg2) throws Exception
{
Map<String, Object> model = new HashMap<String, Object>();
List<Communication> allCommunications = dao.getAllCommunications();
model.put("allCommunications", allCommunications);
model.put("error", ""); //not sure how to get this data
model.put("success", ""); //not sure how to get this data
return model;
}
protected void onSubmitAction(ActionRequest argRequest,
ActionResponse argResponse, Object command, BindException errors)
throws Exception
{
Communication form = (Communication) command;
dao.updateCommunication(form);
//I want to set a success message here that can be read in the JSP
<bean id="communicationsValidator" class="com.admin.portlet.communication.CommunicationsValidator"/>
<bean id="communicationsController" class="com.admin.portlet.communication.CommunicationsAdminController">
<property name="commandName" value="communications"/>
<property name="commandClass" value="com.admin.portlet.communication.vo.Communication"/>
<property name="formView" value="communications/communicationsAdmin"/>
<property name="successView" value="communications/communicationsAdmin"/>
<property name="validator"><ref bean="communicationsValidator"/></property>
<property name="dao"><ref bean="communicationsDao"/></property>
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1"/>
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="communicationsController"/></entry>
</map>
</property>
</bean>
JSP内部产生的异常很难调试,特别是在JSP中根本不使用Scriptlet的情况下。这将表明所使用的标记库中有一个bug,或者业务逻辑中有一个微不足道的配置/流错误,这在后期揭示了这个异常
<bean id="communicationsValidator" class="com.admin.portlet.communication.CommunicationsValidator"/>
<bean id="communicationsController" class="com.admin.portlet.communication.CommunicationsAdminController">
<property name="commandName" value="communications"/>
<property name="commandClass" value="com.admin.portlet.communication.vo.Communication"/>
<property name="formView" value="communications/communicationsAdmin"/>
<property name="successView" value="communications/communicationsAdmin"/>
<property name="validator"><ref bean="communicationsValidator"/></property>
<property name="dao"><ref bean="communicationsDao"/></property>
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1"/>
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="communicationsController"/></entry>
</map>
</property>
</bean>
首先,在appserver的工作目录中找到_communicationsAdmin.java文件,并调查第212行是否存在潜在的空指针,最终将其追溯到潜在的配置/流错误。如果您在调试过程中遇到困难,您也可以在此处仅粘贴相关的“是”行,以便我们可以为您定位。发布堆栈跟踪会很有帮助。感谢您的建议,我现在已经添加了它。感谢您的回复。我不确定为什么要加载jsp。我希望在请求返回到浏览器之前调用referenceData方法?我甚至不知道这是否有意义,但我需要获取一个对象列表,并以与初始加载页面时相同的方式返回它们。此外,我不知道在哪里可以找到JSP的.java版本?我正在搜索我的硬盘,但似乎什么也没找到
<bean id="communicationsValidator" class="com.admin.portlet.communication.CommunicationsValidator"/>
<bean id="communicationsController" class="com.admin.portlet.communication.CommunicationsAdminController">
<property name="commandName" value="communications"/>
<property name="commandClass" value="com.admin.portlet.communication.vo.Communication"/>
<property name="formView" value="communications/communicationsAdmin"/>
<property name="successView" value="communications/communicationsAdmin"/>
<property name="validator"><ref bean="communicationsValidator"/></property>
<property name="dao"><ref bean="communicationsDao"/></property>
</bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1"/>
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="communicationsController"/></entry>
</map>
</property>
</bean>