错误信息如下:
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>
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>
解决方案 »
- ireport5.0 分组无法实现
- 用户注册验证问题
- 使用过Apache commons-net包的朋友请进
- jsp菜鸟问题~
- struts怎么回显<html:file中的文件名称!!!
- 兄弟们~~~~~祝福我吧````明天要上演一天2面了(进来就有分)
- 本地测试没有错,但是移到服务器上就出错了,急求高手救!!
- jsp页面操作地址栏标题不改变
- 项目开发过程中有一般会设置开关变量吗?
- 界面设计?idea?
- 准备把自己做的网站挂到网上,想问下像TOMCAT和MYSQL这样的服务及数据库怎样挂载到网上~~~
- 性能比较:rs.last;rs.getRow(); 和select count(id) from table
我怀疑是不是配置文件方面部分有问题,我那四个值都输出了,都有值,很正常
就是在第十句报空指针,无奈了
多谢大家的帮助!