配置如下:MyEclipse7.1 jdk1.6 tomcat5.5 struts 1.2 spring2.5 hibernate3.2
错误如下:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause java.lang.NullPointerException
com.pt.struts.action.StudentLoginAction.execute(StudentLoginAction.java:47)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
--------------------------------------------------------------------------------
这是我后台dao中调用到的函数:
public Student getStudentByEmail(String email) {
System.out.println("test, the function getStudentByEmail is getin" +
" and the email is "+email);
String hql = "FROM Student WHERE studentEmail = '";
hql += email;
hql+="'";
Student student = null;
List list =null;
try{
list = ht.find(hql);
System.out.println("test , we get the list, the size of list is "+list.size());
student = (Student)list.get(0);
}
catch(Exception ex)
{
ex.getStackTrace();
}
return student;
}我debug了一下,语句System.out.println("test, the function getStudentByEmail is getin" +" and the email is "+email);能够打印,而后面的语句:System.out.println("test , we get the list, the size of list is "+list.size());不能够打印。申明email不是主码,hql语句没有写错。
错误如下:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause java.lang.NullPointerException
com.pt.struts.action.StudentLoginAction.execute(StudentLoginAction.java:47)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
--------------------------------------------------------------------------------
这是我后台dao中调用到的函数:
public Student getStudentByEmail(String email) {
System.out.println("test, the function getStudentByEmail is getin" +
" and the email is "+email);
String hql = "FROM Student WHERE studentEmail = '";
hql += email;
hql+="'";
Student student = null;
List list =null;
try{
list = ht.find(hql);
System.out.println("test , we get the list, the size of list is "+list.size());
student = (Student)list.get(0);
}
catch(Exception ex)
{
ex.getStackTrace();
}
return student;
}我debug了一下,语句System.out.println("test, the function getStudentByEmail is getin" +" and the email is "+email);能够打印,而后面的语句:System.out.println("test , we get the list, the size of list is "+list.size());不能够打印。申明email不是主码,hql语句没有写错。
解决方案 »
- struts2中,cookie保存操作,在哪操作比较好呢?
- 使用jsp smartupload组件做下载,迅雷下载的异常socket write error,哪位高人能搞定,请不吝赐教,在下感激涕零。在线狂等中...
- 今天下午的面试题目,求解........
- ?
- 怪事 apache2.0.43+tomcat4+struts+log4j 结果找不到log4j的包!
- 上传图片时出错,我找不出错误所在,高手帮忙看看呀!!!
- JSP 文件修改后,怎么让它在浏览器中马上反映出来?马上结帖!!!!!
- 菜鸟问各位高手,JSP中JavaBean的问题?
- 请问单独用resin和用apache+resin有什么不同?
- 手机输入验证跳转的问题
- 请教一下DAO设计的问题.
- tomcat的问题,
设个断点看看 那个值没有得到
是空指针
<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.5.xsd"> <bean id="studentDao" class="com.pt.dao.StudentDao">
<property name="sessionFactory">
<ref local ="sessionFactory"/>
</property>
</bean> <bean name="/studentLogin" class="com.pt.struts.action.StudentLoginAction" >
<property name="studentDao">
<ref local="studentDao"/>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
</bean>
</beans>
ht没有初始化。
如果查询结果为空的话,list=null;
直接取第一个元素会报错。
建议修改为:
if(list!=null&&list.size()>0){
student = (Student)list.get(0);
}
com.pt.struts.action.StudentLoginAction.execute(StudentLoginAction.java:47) 你返回的对象为空,list为空,用list去操作当然会空指针。
自己处理下异常
if(list!=null&&list.size!=0)
{
再做操作。
}
list = ht.find(hql);从在找问题
public class StudentDao extends HibernateDaoSupport implements IStudentDao {
HibernateTemplate ht = this.getHibernateTemplate();
public Student getStudentByEmail(String email) {
这个应该是这样初始化吧!下面的内容就是上面贴的函数的代码了!
这一句的时候,就直接跳到catch(Exception ex)
{
ex.getStackTrace();
}
了。
八楼的朋友我没有懂你说的是什么意思!
好像你没有配置啊
不知道是不是完整的配置文件
这样应该tomcat都不能启动啊
从这下手一点点的找,调错需要耐心
public Student getStudentByEmail(String email) {
System.out.println("test, the function getStudentByEmail is getin" +
" and the email is "+email);
String hql = "FROM Student WHERE studentEmail = '";
hql += email;
hql+="'";
Student student = null;
List list =null;
try{
//添加了下面这一句
ht = this.getHibernateTemplate();//这里为修改的地方 list = ht.find(hql);
System.out.println("test , we get the list, the size of list is "+list.size());
student = (Student)list.get(0);
}
catch(Exception ex)
{
ex.getStackTrace();
}
return student;
}
(我在hibernate配置文件中配置了show_sql为true)可以打印出select语句了(以前不行),但还是错误!
你现在能够获取到ht了吗?
如果能还报错,把错误帖出来
log4j.rootLogger=info,A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.Append=true
log4j.appender.A1.File=F:/Workspaces7.1/log4j.log
log4j.appender.A1.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH\:mm\:ss} Method\: %l%n%m%n
其中log4j.appender.A1.File是你输出文件的路径。