错误信息如下: 
message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: java.lang.NullPointerException 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) 
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) 
..........意思我懂,就是在第十行有空指针异常,不过我都输出这几个参数了,都有值。它也没执行Service层的save()方法,应该就是第十行有问题!仔细检查了配置文件也没发现什么....究竟哪儿出问题了呢?请大家指点,多谢! 
ACTION部分: Java代码 
public String  upload(){   
        String dstPath=ServletActionContext.getServletContext()   
                  .getRealPath(this.getFilePath()) + "\\" + this.getUploadFileName();   
        File dstFile = new File(dstPath);    
        copy(this.getUpload(), dstFile);   
        System.out.print(" uploadFileName "+uploadFileName);   
        System.out.print(" dstPath "+dstPath);   
        System.out.print(" fileRe "+fileRe);   
        System.out.print(" fileAuthor "+fileAuthor);   
                  fileService.save(uploadFileName, dstPath, fileRe, fileAuthor);   
        return SUCCESS;   
    }  public String  upload(){
String dstPath=ServletActionContext.getServletContext()
      .getRealPath(this.getFilePath()) + "\\" + this.getUploadFileName();
File dstFile = new File(dstPath); 
copy(this.getUpload(), dstFile);
System.out.print(" uploadFileName "+uploadFileName);
System.out.print(" dstPath "+dstPath);
System.out.print(" fileRe "+fileRe);
System.out.print(" fileAuthor "+fileAuthor);
                  fileService.save(uploadFileName, dstPath, fileRe, fileAuthor);
return SUCCESS;
}配置文件applicationContext.xml部分: Java代码 
<?xml version="1.0" encoding="UTF-8"?>   
<beans   
    xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">   
       
    <!-- 定义数据源Bean,使用C3P0数据源实现 -->   
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">   
        <!-- 指定连接数据库的驱动 -->   
        <property name="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>   
        <!-- 指定连接数据库的URL -->   
        <property name="jdbcUrl" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"/>   
        <!-- 指定连接数据库的用户名 -->   
        <property name="user" value="sa"/>   
        <!-- 指定连接数据库的密码 -->   
        <property name="password" value="123"/>   
        <!-- 指定连接数据库连接池的最大连接数 -->   
        <property name="maxPoolSize" value="20"/>   
        <!-- 指定连接数据库连接池的最小连接数 -->   
        <property name="minPoolSize" value="1"/>   
        <!-- 指定连接数据库连接池的初始化连接数 -->   
        <property name="initialPoolSize" value="1"/>   
        <!-- 指定连接数据库连接池的连接的最大空闲时间 -->   
        <property name="maxIdleTime" value="20"/>   
    </bean>   
       
    <!--定义了Hibernate的SessionFactory -->   
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   
        <property name="dataSource" ref="dataSource"/>   
        <property name="mappingResources">   
            <list>   
                <value>com\model\TFile.hbm.xml</value>   
            </list>   
        </property>   
        <property name="hibernateProperties">   
            <props>   
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>   
                <prop key="show_sql">true</prop>   
                <prop key="hibernate.hbm2ddl.auto">update</prop>   
                <prop key="hibernate.jdbc.batch_size">20</prop>    
            </props>   
        </property>   
    </bean>   
     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">   
        <property name="sessionFactory" ref="sessionFactory"/>   
    </bean>   
       
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">   
        <!--  事务拦截器bean需要依赖注入一个事务管理器 -->   
        <property name="transactionManager" ref="transactionManager"/>   
        <property name="transactionAttributes">   
            <!--  下面定义事务传播属性-->   
            <props>   
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>   
                <prop key="*">PROPAGATION_REQUIRED</prop>   
            </props>   
        </property>   
    </bean>   
  
    <!-- 定义BeanNameAutoProxyCreator-->   
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">   
        <!--  指定对满足哪些bean name的bean自动生成业务代理 -->   
        <property name="beanNames">   
            <!--  下面是所有需要自动创建事务代理的bean-->   
            <list>   
                <value>fileService</value>   
            </list>   
            <!--  此处可增加其他需要自动创建事务代理的bean-->   
        </property>   
        <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->   
        <property name="interceptorNames">   
            <list>   
                <!-- 此处可增加其他新的Interceptor -->   
                <value>transactionInterceptor</value>    
            </list>   
        </property>   
    </bean>   
    <bean id="fileDao" class="com.dao.TFileDAOImpl">   
        <property name="sessionFactory" ref="sessionFactory"/>   
    </bean>   
    <bean id="fileService" class="com.service.FileServiceImpl">   
        <property name="fileDao" ref="fileDao"/>   
    </bean>   
</beans>  

解决方案 »

  1.   

    用struts2的FileUtils.copyFile(uploadFile, target); 直接上传文件
      

  2.   

    空指针的话,最好是自己debug下!
      

  3.   

    smartupload, 空指针异常其实完全可以测试出来
      

  4.   

    它也没执行Service层的save()方法
    我怀疑是不是配置文件方面部分有问题,我那四个值都输出了,都有值,很正常
    就是在第十句报空指针,无奈了
      

  5.   

    问题终于解决了!原来是没加载struts2-spring-plugin-2.0.11这个包!呵呵,高兴啊 
    多谢大家的帮助!
      

  6.   

    我今天也遇到这个问题了!!看到你这个帖子才知道是没加载struts2-spring-plugin-2.0.11这个包。。我想请教你下,这个你是怎么看出来是没加载struts2-spring-plugin-2.0.11这个包的。。