首页 > Java, Struts2 > Struts2常见异常与分析处理【不断更新】

Struts2常见异常与分析处理【不断更新】

      1、ognl.OgnlException: target is null for setProperty

      分析处理:

      在action中有:

private transient Filmrlspack filmrlspack;
/**
 *这里省略了getter、setter方法的代码
 */

      提交数据的表单代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<form method="post" name="wmfForm" id="wmfForm" action="">
<span id="wmf-msg"></span>
<table width="700" border="0" cellspacing="0" cellpadding="0" class="sample">
  <tr>
    <td>影片发行版名称:</td>
    <td><input type="text" readonly="readonly" name="Filmrlspack.filmname" value="<%=request.getParameter("filmname") %>" /></td>
    <td>业务类型:</td>
    <td><input type="hidden" name="businesstypeID"  value="<%=request.getParameter("businesstypeID") %>" /><input type="text" name="businesstypeName" readonly="readonly" value="<%=request.getParameter("businesstypeName") %>" /></td>
  </tr>
  <tr>
    <td>出品单位:</td>
    <td><input type="text" name="Filmrlspack.manufacture" /></td>
    <td>出品年代:</td>
    <td><input type="text" name="Filmrlspack.manufacturedate" /></td>
  </tr>
  <tr>
    <td>导演:</td>
    <td><input type="text" name="Filmrlspack.directors" /></td>
    <td>主演:</td>
    <td><input type="text" name="Filmrlspack.leaderact" /></td>
  </tr>
  <tr>
    <td>语种:</td>
    <td><input type="text" name="Filmrlspack.langtype" /></td>
    <td>是否主语种:</td>
    <td><input type="checkbox" name="Filmrlspack.maintype" value="1" checked="checked" /></td>
  </tr>
  <tr>
    <td>影片描述:</td>
    <td colspan="3"><textarea rows="5" cols="75"  name="Filmrlspack.filmname" ></textarea></td>
  </tr>
</table>
</form>

      其中很多字段为非必填字段,若什么都不填提交到action中为null,报以上异常。

      把action中的

private transient Filmrlspack filmrlspack;
/**
 *这里省略了getter、setter方法的代码
 */

      改成

private transient Filmrlspack filmrlspack = new Filmrlspack();
/**
 *这里省略了getter、setter方法
 */

      就可以了。

      2、Caused by: There is no result type defined for type ‘redirect-action’ mapped with name

      分析处理:

      在struts.xml中配置如下:

<global-results>
	<result name="login" type="redirect-action">redirectLoginAction</result>
</global-results>

       报以上异常,用的Struts2包版本为2.1.8.1,后来查看了jar包中的struts-default.xml,发现type中没有redirect-action这一类型,而是变成了redirectAction,把type=”redirect-action”改成type=”redirectAction”就不会有这个异常了。

      (2010年1月19日更新)

      3、待更新…

      分析处理:

  1. 2010年4月11日06:01 | #1
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。