首页 新闻 会员 周边 捐助

用SSH写一个简单的登录,一直报空指针,大神青睐解救新人

0
悬赏园豆:50 [待解决问题]
自己写的一个SSH简单的登录,可是一直报空指针,表单数据也接受不到,数据库的数据也看不到,求大神解答
 
   <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean> 
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="driverClassName" value="${jdbc.driverClassName}"></property>

<property name="maxActive"> <value>100</value></property>
      <property name="maxIdle"> <value>30</value> </property>
      <property name="maxWait"> <value>10000</value> </property>


</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format">true</prop>
<prop key="hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/wzl/o/domain/Student.hbm.xml</value>
</list>
</property></bean>



<!-- 配置action -->
<bean id="studentAction" class="com.wzl.o.action.StudentAction" scope="prototype" >
<property name="studentService" ref="studentService"></property>

</bean>
<!-- 配置service -->
<bean id="studentService" class="com.wzl.o.serviceImpl.StudentServiceImpl" scope="prototype">
<property name="studentDao" ref="studentDao"></property>
</bean>

<!-- 配置dao -->
<bean id="studentDao" class="com.wzl.o.daoImpl.StudentDaoImpl" scope="prototype">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" /></beans>
applicationContext.xml:
 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<!-- 该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。
如果需要关闭动态方法调用,则可设置该属性为false。    
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
           把它设置为开发模式,发布时要设置为false 
    <constant name="struts.devMode" value="true" />
-->
    <package name="default" namespace="/" extends="struts-default">
<action name="student_*" class="com.wzl.o.action.StudentAction" method="{1}" >
<result name="login_result">/index.jsp</result>
<result name="login_error">/index.jsp</result>
</action>
</package>

</struts>
package com.wzl.o.action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.wzl.o.domain.Student;
import com.wzl.o.service.StudentService;

public class StudentAction extends ActionSupport implements ModelDriven<Student>{
private StudentService studentService;
private Student student;
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
public String login(){
System.out.println(student.getPassword());
//    Student student1=studentService.findByUsername(student);
System.out.println("1");
//    if(student1==null){
//    System.out.println("1");
//
//    this.addActionError("用户名或者密码错误");
//    return "login_error";
//    }else{
return "logim_success";
//    }    
}
public Student getModel() {
//    System.out.println(this.student.getPassword());
return this.student;
}    
 }
package com.wzl.o.daoImpl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.wzl.o.dao.StudentDao;
import com.wzl.o.domain.Student;

public class StudentDaoImpl implements StudentDao {
private    SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Student findByUsername(Student student) {
String hql = "from Employee where username=? and password=?";    
Session session = sessionFactory.openSession();
Query query = session.createQuery(hql);
query.setString(0, student.getUsername());
query.setString(1, student.getPassword());

List<Student> list = query.list();
if(list.size()>0){
return list.get(0);
}else{
System.out.println(list.get(0));
list=null;
System.out.println(list.get(0));
return list.get(0);
}

}

}
java.lang.NullPointerException
com.wzl.o.action.StudentAction.getModel(StudentAction.java:33)
com.wzl.o.action.StudentAction.getModel(StudentAction.java:1)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:92)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:140)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)

求大神解答,困扰了好几天了,找不到出路,学编程的信心都快被打击死了

努力小码的主页 努力小码 | 初学一级 | 园豆:146
提问于:2016-10-20 20:12
< >
分享
所有回答(4)
0

不会调试???

顾晓北 | 园豆:10898 (专家六级) | 2016-10-21 09:40

不会调!

支持(0) 反对(0) 努力小码 | 园豆:146 (初学一级) | 2016-10-21 15:42
0

你的jsp页面和实体类是怎样的

寒塘渡鹤影冷月葬花魂 | 园豆:211 (菜鸟二级) | 2016-10-22 12:47
0

一般这种问题多数都是jsp页面的input的名字与你的实体类的属性名不相等,或者是action中的getmodel的方法没有返回,但我看了一下你的action应该没有问题,你因该看一下你的jsp页面和实体类,然后在action先输出对象的信息,看有没有获取到输入信息在开始写登录方法,不要一口气写完,那样十分容易出错。

奔跑的毛毛 | 园豆:202 (菜鸟二级) | 2016-10-25 17:41
0

hibernate4.3.5.Final你好  ,你能给我发一个这个资源吗?yang_shuang163@163.com  

YOYOYS | 园豆:210 (菜鸟二级) | 2017-10-14 01:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册