求助

   在用struts进行bean拷贝的时候,出现空指针异常,我用的是MyEclipse5.1和resin2.1.7服务器 下面我吧我的action和copybean代码发过来,请各位前辈给指点到低是哪里的问题,先谢谢啦

    action代码

         public class UserAction extends Action {
 /*
  * Generated Methods
  */

 
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  // TODO Auto-generated method stub
  UserActionForm uf = (UserActionForm)form;
  UserDto ut = new UserDto();
  CopyBean cb = new CopyBean();
  try {
   cb.copyAttribute(uf, ut);
  } catch (IllegalArgumentException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  UserServer us = new UserServerImpl();
  us.addUser(ut);
  String str = "suce";
  return mapping.findForward(str);
 }
}

                  bean拷贝代码

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class CopyBean {
    public static Object copyAttribute(Object source,Object dest) throws
            InvocationTargetException, IllegalArgumentException,
            IllegalAccessException {

        String sourceMethodName = null;
        String sourceMethodFix = null;
        String destMethodName = null;
        String destMethodFix = null;
        Method[] sourceMethod=source.getClass().getMethods();
        Method[] destMethod=dest.getClass().getMethods();
        for(int i=0;i<sourceMethod.length;i++){
          sourceMethodName=sourceMethod[i].getName();
          sourceMethodFix=sourceMethodName.substring(3);
          if(sourceMethodName.startsWith("get")){
            for(int n=0;n<destMethod.length;n++){
               destMethodName=destMethod[n].getName();
               destMethodFix=destMethodName.substring(3);
                 if(destMethodName.startsWith("set")){
                    if(sourceMethodFix.equals(destMethodFix)){
                        Object[] sourceArray=new Object[0];
                        Object[] destArray=new Object[1];
                        //激活source的相应的get的方法,sourceArray数组存放调用该方法的参数,此例中没有参数,该数组的长度为0
                        destArray[0]=sourceMethod[i].invoke(source,sourceArray);
                         //激活dest的相应的set的方法,destArray数组存放调用该方法的参数
                         destMethod[n].invoke(dest,destArray);
                          continue;
                        }
                    }
                }
            }
        }
        return dest;
    }
}

   出的异常是这样的

500 Servlet Exception

java.lang.NullPointerException
	at util.CopyBean.copyAttribute(CopyBean.java:15)
	at action.UserAction.execute(UserAction.java:40)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:165)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
	at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
	at com.caucho.server.http.Invocation.service(Invocation.java:315)
	at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:253)
	at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:171)
	at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
	at java.lang.Thread.run(Thread.java:534)
   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值