`
tangxininjava
  • 浏览: 96638 次
  • 性别: Icon_minigender_1
  • 来自: 遂宁
社区版块
存档分类
最新评论

struts2错误source is null for getProperty(null, "0")

    博客分类:
  • J2EE
阅读更多

首先简单描述下: 

首先我用的springside-3.3.4中的CrudActionSupport 用简单的对象(意思是对象里面没有对象就不会报错,而对象里面有对象的就会报错,我里面用了List)

我先说下对象关系吧用代码:

 

package com.tang.flight.vo.custom;

import java.util.List;

import com.tang.flight.vo.DomeTicketFlight;
import com.tang.flight.vo.ThirdPolicyItem;

public class OrderVo {
	
	private String orderNo;
	
	
	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	private List<DomeTicketFlight> flights;
	
	private List<ThirdPolicyItem> thirdPolicyItems;

	public List<DomeTicketFlight> getFlights() {
		return flights;
	}

	public void setFlights(List<DomeTicketFlight> flights) {
		this.flights = flights;
	}

	public List<ThirdPolicyItem> getThirdPolicyItems() {
		return thirdPolicyItems;
	}

	public void setThirdPolicyItems(List<ThirdPolicyItem> thirdPolicyItems) {
		this.thirdPolicyItems = thirdPolicyItems;
	}
	
	

}

 

 

 

package com.tang.flight.actions.order;

import java.util.ArrayList;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.tang.flight.actions.CrudActionSupport;
import com.tang.flight.vo.DomeTicketFlight;
import com.tang.flight.vo.ThirdPolicyItem;
import com.tang.flight.vo.custom.OrderVo;

@Namespace("/order")
@Results({@Result(type="redirect",location="manager.action",name=CrudActionSupport.RELOAD)})
public class ManagerAction extends CrudActionSupport<OrderVo> {

	private static final long serialVersionUID = -6137449398836451112L;
	
	
	private Long id;
	
	
	
	
	public void setId(Long id) {
		this.id = id;
	}

	private OrderVo entity;
	
	
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return SUCCESS;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (id!=null) {
			
		}else{
			entity = new OrderVo();
			ArrayList<DomeTicketFlight> flights = new ArrayList<DomeTicketFlight>(0);
			flights.add(new DomeTicketFlight());
			entity.setFlights(flights);
			ArrayList<ThirdPolicyItem> thirdPolicyItems = new ArrayList<ThirdPolicyItem>(0);
			thirdPolicyItems.add(new ThirdPolicyItem());
			entity.setThirdPolicyItems(thirdPolicyItems);
		}
		
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		System.out.println(entity);
		return RELOAD;
	}

	public OrderVo getModel() {
		// TODO Auto-generated method stub
		return entity;
	}

	
	

}

 

    

<#assign s=JspTaglibs["/WEB-INF/struts-tags.tld"] />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <body>
	<h1></h1>
	<@s.form action="manager!save.action" theme="simple">
		<@s.textfield label="fltNo" title="fltNo"  name="flights[0].fltNo"   theme="simple"/>
		<@s.textfield title="fltNo" name="thirdPolicyItems[0].protocolNo" theme="simple" />
		<@s.textfield label="orderNo" title="orderNo"  name="orderNo"   theme="simple"/>
		<@s.submit theme="simple"/>
	</@s.form>
	
	
	
  </body>
</html>

 

   save方法保存之前会执行

@Override
	protected void prepareModel() throws Exception {
		if (id!=null) {
			
		}else{
			entity = new OrderVo();
			ArrayList<DomeTicketFlight> flights = new ArrayList<DomeTicketFlight>(0);
			flights.add(new DomeTicketFlight());
			entity.setFlights(flights);
			ArrayList<ThirdPolicyItem> thirdPolicyItems = new ArrayList<ThirdPolicyItem>(0);
			thirdPolicyItems.add(new ThirdPolicyItem());
			entity.setThirdPolicyItems(thirdPolicyItems);
		}
		
	}

 

   很奇怪这里面的entity是空的,然后到下面这个方法时又不是空的

@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		System.out.println(entity);
		return RELOAD;
	}

 
 

下面的这个错误是在prepareModel这个方法报的

 

2013-01-24 14:33:46,170 [http-8083-1] WARN  [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'flights[0].fltNo' with value '[Ljava.lang.String;@179d47f'

ognl.OgnlException: source is null for getProperty(null, "0")

at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2293)

at ognl.ASTProperty.getValueBody(ASTProperty.java:114)

at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

at ognl.SimpleNode.getValue(SimpleNode.java:258)

at ognl.ASTChain.setValueBody(ASTChain.java:222)

at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)

at ognl.SimpleNode.setValue(SimpleNode.java:301)

at ognl.Ognl.setValue(Ognl.java:737)

at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:217)

at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)

at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)

at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)

at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)

at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)

at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:194)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)

at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)

at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)

at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Thread.java:662)

2013-01-24 14:33:46,173 [http-8083-1] WARN  [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'thirdPolicyItems[0].protocolNo' with value '[Ljava.lang.String;@22ed4b'

ognl.OgnlException: source is null for getProperty(null, "0")

at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2293)

at ognl.ASTProperty.getValueBody(ASTProperty.java:114)

at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

at ognl.SimpleNode.getValue(SimpleNode.java:258)

at ognl.ASTChain.setValueBody(ASTChain.java:222)

at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)

at ognl.SimpleNode.setValue(SimpleNode.java:301)

at ognl.Ognl.setValue(Ognl.java:737)

at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:217)

at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)

at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)

at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)

at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)

at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)

at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:194)

at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)

at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)

at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)

at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)

at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Thread.java:662)

com.tang.flight.vo.custom.OrderVo@98746b

分享到:
评论

相关推荐

    struts2 sort实例

    Struts2是一个强大的MVC(模型-视图-控制器)框架,广泛应用于Java Web开发中。在Struts2中,提供了丰富的标签库来简化视图层的开发,其中包括`sort`标签,它允许我们在JSP页面上对数据集合进行排序。这个实例将深入...

    struts2连接mysql多表查询

    Struts2是一个基于MVC(Model-View-Controller)设计模式的Java Web框架,它主要用于构建企业级的Web应用程序。在Struts2中,我们常常需要与数据库进行交互,MySQL是一个广泛使用的开源关系型数据库管理系统,它在...

    struts2讲义_吴峻申

    Struts2讲义 作者:吴峻申 目录 第1章 Struts过时了吗? 10 1.1 Struts历史发展过程 10 1.2 Struts2的“简历” 13 1.2.1 标签库介绍 13 1.2.2 拦截器应用目的 14 1.2.3 FilterDispatcher和Action概述 14 1.2.4 ...

    struts2对Ognl的封装--PropertyAccessor

    Struts2是一个流行的Java web框架,它极大地简化了MVC(模型-视图-控制器)架构的实现。在Struts2中,OGNL(Object-Graph Navigation Language)是一种强大的表达式语言,用于获取和设置对象的属性。"struts2对Ognl...

    Struts上传文件实现代码

    Struts2是一个流行的Java web开发框架,用于构建可维护、可扩展且结构良好的应用程序。在Struts2中,实现文件上传功能是常见的需求,尤其是在处理用户提交的表单时,如上传图片、文档等。本篇文章将深入探讨如何在...

    Struts2下多文件的上传与下载

    ### Struts2下多文件的上传与下载 #### 写在前面 在互联网技术领域,文件上传和下载是一项常见的功能需求。Struts2作为一个成熟且功能丰富的Java Web应用框架,为开发者提供了便捷的方法来实现这一功能。然而,...

    jsp到struts2总结.docx

    【JSP到Struts2总结】 JSP(Java Server Pages)是基于Java技术的一种服务器端网页编程技术,用于创建跨平台、跨Web服务器的动态网页。JSP网页由HTML、JavaScript、Java程序片段(scriplet)和JSP标记(tag)组成。...

    Struts网站计数器(附带数据库文件)

    Struts是一个著名的Java Web开发框架,由Apache软件基金会维护,主要用于构建基于MVC(Model-View-Controller)设计模式的Web应用程序。这个“Struts网站计数器”项目显然是一个用Struts实现的简单功能,它能记录并...

    struts验证器validator使用,以及自定义验证器

    5. **处理验证结果**:在Action类中,Struts会自动调用验证器,如果验证失败,Action的execute方法不会执行,而是返回“input”结果,可以在JSP页面中显示错误信息。 **三、自定义验证器** 当内置的验证规则不能...

    Struts上传,已经处理好乱码问题

    Struts框架是Java Web开发中常用的一个开源框架,主要用于构建基于MVC(Model-View-Controller)模式的应用程序。在Struts框架中,文件上传功能是常见的需求之一,尤其是在处理用户提交的表单数据时。然而,文件上传...

    Struts02-001简单分析1

    Struts2是一个流行的Java web应用框架,用于构建和维护MVC(模型-视图-控制器)结构的应用程序。本文将详细分析Struts2中的一个重要安全漏洞,即S2-001漏洞,以及其影响、原理、修复措施,并提供相关的POC(Proof of...

    Struts 页码

    在上述代码中,我们使用了Struts2的标签来生成链接,传递当前页码作为请求参数,Action会根据这个参数更新`Pages`对象,并返回新的数据列表。 总结起来,Struts框架中的分页实现主要涉及模型层的分页计算、控制器层...

    Jsp+JavaBean+Struts+JDBC,数据库:MySQL信息管理系统

    **JSP+JavaBean+Struts+JDBC与MySQL数据库集成的信息管理系统** 在Web开发领域,JSP(JavaServer Pages)常用于构建动态网页,JavaBean作为Java对象模型,Struts作为MVC(Model-View-Controller)框架,而JDBC...

    System.getProperty

    System.getProperty 通过该方法获取系统属性信息 很好

    DButil.java

    Class.forName(info.driver); String url="jdbc:sqlserver://" + info.host + ":" + info.point + ";databaseName=" + info.dbName; conn=DriverManager.getConnection(url,info.userName,info.userPass); } ...

    数据连接池

    String maxconn = props.getProperty(poolName + ".maxconn", "0"); int max; try { max = Integer.valueOf(maxconn).intValue(); } catch (NumberFormatException e) { log("错误的最大连接数限制: " + ...

    struts课件ppt

    2. **Action类**:在Struts中,Action类是处理用户请求的核心,它接收来自表单的请求参数,执行相应的业务逻辑,并返回一个表示下一步动作的ActionForward对象。 3. **配置文件**:Struts应用通过struts-config.xml...

    C# webbrowser捕获错误页面实例类

    int statusCode = (int)wb.Document.Window.DomWindow.GetProperty("location").GetProperty("statusCode"); if (statusCode &gt;= 400 && statusCode ) { HandleError(new WebBrowserError { StatusCode = status...

    struts标签库总结

    总之,Struts标签库提供了一系列强大的工具,帮助开发者构建更加结构化的JSP页面,提高了开发效率,减少了错误的可能性。无论是处理Bean、控制逻辑还是显示数据,都有对应的标签来简化工作。通过熟练掌握这些标签的...

    struts文件上传(源代码)

    Struts框架是Java Web开发中常用的一个开源框架,它提供了模型-视图-控制器(MVC)模式的实现,使得开发者能够更有效地构建可维护、可扩展的Web应用程序。在这个"struts文件上传(源代码)"的例子中,我们将探讨如何在...

Global site tag (gtag.js) - Google Analytics