import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
import com.wgz.friend.entity.Userinfo;
import com.wgz.friend.service.LoginService;
import com.wgz.friend.service.UserinfoService;
public class UserInfoBean extends BaseMBean { private Userinfo userinfo = new Userinfo();
private LoginService loginService;
private UserinfoService userinfoService;
private List<Userinfo> userinfoList;

public UserinfoService getUserinfoService() {
//if(userinfoService==null){
//ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//userinfoService = (UserinfoService) context.getBean("userinfoService");
}
return userinfoService; 
}
public void setUserinfoService(UserinfoService userinfoService) {
this.userinfoService = userinfoService;
}
public Userinfo getUserinfo() {
return userinfo;
}
public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}
public LoginService getLoginService() {
//if(userinfoService==null){
//ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//userinfoService = (UserinfoService) context.getBean("loginService");
}
return loginService;
}
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
public List<Userinfo> getUserinfoList() {
return userinfoList;
}
public void setUserinfoList(List<Userinfo> userinfoList) {
this.userinfoList = userinfoList;
}
public String verify(){
if((userinfo.getUsername().equals("admin"))&&(userinfo.getUserpassword().equals("wgz"))){
return "admin";

else{

return loginService.check(userinfo.getUsername(), userinfo.getUserpassword());
}

}
public void delete(Userinfo userinfo){
try {
userinfoService.delete(userinfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<Userinfo> findFriend(){
userinfoList = userinfoService.findFriendList(userinfo);
return userinfoList;
}
public String register() throws Exception{
System.out.println(userinfo.getUsername());
System.out.println(userinfo);
return userinfoService.save(userinfo);
//this.message = "注册成功";
}

public String stepDetail(){
Integer userid = 
                Integer.parseInt((String) getRequestParameter("searchTitle"));
this.userinfo = userinfoService.findById(userid);
                return "stepview";
    }
}
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/fridend" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
destroy-method="close">
<property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list>
<value>com.wgz.friend.entity.Userinfo.hbm.xml</value>
<value>
com.wgz.friend.entity.Invatepeople.hbm.xml
</value>
</list>
</property> <property name="hibernateProperties"> <props>
<prop key="hibernate.dialect">
org.hibernate.dialect.DerbyDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="LoginService" class="com.wgz.friend.LoginServiceimpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userinfoservice" class="com.wgz.friend.serviceimpl.UserinfoServiceImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
UserinfoBean 的verify()方法获取loginService时,报错误
javax.faces.FacesException: #{userInfoBean.verify}: javax.faces.el.EvaluationException: java.lang.NullPointerException
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)在线等解决方法,,,毕业设计要用,急,,,在线等谢谢

解决方案 »

  1.   

    ActionListenerImpl.java:78
    自己断点DEBUG去跟踪呀 空指针异常都是这么改的
      

  2.   

    我知道那个地方的错,,,
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
    就是不知道改怎么写,,,第一次自己写东西,卡好几天了,,,,求帮忙
      

  3.   

    <%@ page language="java" pageEncoding="GBK"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head> <title>登录</title>
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    --> </head> <body>
    <f:view>
    <h:form>
    <h:panelGrid columns="2" border="1" cellpadding="5" cellspacing="3">
    <h:panelGrid columns="3" border="1" cellpadding="5" cellspacing="3"
    headerClass="login-heading" style="height: 325px; width: 337px">
    <f:facet name="header">
    <h:outputText value="欢迎登陆聚梦交友聚会网站"></h:outputText>
    </f:facet>
    <h:outputText value="用户名:"></h:outputText>
    <h:inputText id="userNameInput" size="30" maxlength="20"
    value="#{userInfoBean.userinfo.username}" style="width: 104px">
    </h:inputText>
    <h:message for="userNameInput"></h:message>
    <h:outputText value="密码:"></h:outputText>
    <h:inputSecret id="passwordInput" size="30" maxlength="20"
    value="#{userInfoBean.userinfo.userpassword}" style="width: 107px">
    </h:inputSecret>
    <h:message for="passwordInput"></h:message>
    <h:commandButton value="登录" action="#{userInfoBean.verify}" title="submit" style="width: 83px"></h:commandButton>
    <h:commandButton value="注册" action="register1" title="register" style="width: 110px"></h:commandButton>
    </h:panelGrid>
    <h:graphicImage url="/images/login1.jif" alt="welcome to here"
    title="welcome to here" width="149" height="160"
    style="width: 503px; height: 453px">
    </h:graphicImage>
    </h:panelGrid>
    </h:form>
    </f:view>
    </body>
    </html>
      

  4.   

    <h:commandButton value="登录" action="#{userInfoBean.verify}" title="submit" style="width: 83px"></h:commandButton>
    运行到这个地方的时候,出现了错误,
    你看看是怎么个情况
      

  5.   

    在verify的第一行下个断点,监视一下userinfo的属性和方法执行
      

  6.   

    看userinfo.getUsername()和userinfo.getUserpassword()能不能得到
      

  7.   

    建议你导入标签库的时候,别名最好写规范的
    一开始看H。。我还以为什么来着的呢,建议你写html别名。。
      

  8.   

    看着使用的应该是JSF吧,
    action="#{userInfoBean.verify}"首先看看JSF的配置文件中有没有userInfoBean这个配置;
    其次就是上面说的看看public String verify()方法能否执行到...
      

  9.   

    可以通过action="#{userInfoBean.verify}"进入,我在verify()中打印userinfo.username,能出来,问题出在UserinfoBean中通过applicationContext.xml获得LoginService接口
      

  10.   

    应该是你配置的LoginService时出现的问题,要么是LoginService的配置不对,要么是在LoginService中调用的DAO配置不对,你仔细检查下配置,空指针一般就出现在这
      

  11.   

    你用的是jsf,我倒是知道一些。你应该把重点放到逻辑处理上,既然这里出错了,那就写一个简单的测试在相关的处理部分试试到底是怎么回事啊
      

  12.   

    你有没有把userinfobean交给spring管理?
      

  13.   

    你应该没有把LoginService UserinfoService 配置到Spring管理中
      

  14.   

    对于java.lang.NullPointerException 的问题,基本上是因为对null的对象操作了
    所以很可能是userinfo.getUsername()或者userinfo.getUserpassword()获得的事null (具体原因可能是客户端传值出问题了吧,自己去解决)
    public String verify(){
    if((userinfo.getUsername().equals("admin"))&&(userinfo.getUserpassword().equals("wgz"))){
    return "admin";
    }  在服务器端肯定要排除这种情况,所以此时先判断是否null后在调用 equals()方法
    public String verify(){
    if(userinfo.getUsername()!=null)&&(userinfo.getUserpassword()!=null){
     if((userinfo.getUsername().equals("admin"))&&(userinfo.getUserpassword().equals("wgz"))){
      return "admin";
     }
      

  15.   

    没看到你有往UserInfoBean里注入loginService啊
      

  16.   

    不用看就知道是有些东西没注入进去,还有人家要你发,java类错误的地方 你发个页面干什么
      

  17.   


    private LoginService loginService;
    private UserinfoService userinfoService;楼主可以尝试下,把这个两个service的get方法删掉,只保留set方式 试试看....
      

  18.   

    <bean id="LoginService" class="com.wgz.friend.LoginServiceimpl">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
     
    改成 loginService 再试试
      

  19.   


    <%@ taglib uri='http://java.sun.com/jsf/core' prefix='f' %>
    <%@ taglib uri='http://java.sun.com/jsf/html' prefix='h' %>
    <%@ page contentType="text/html; charset=UTF-8"%><html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <f:view>
      <h:form>
       <h:outputLabel value="用户名" /><h:inputText value="#{bangding.name}"/>
    <h:outputLabel value="密码" /><h:inputSecret value="#{bangding.password}"/>
    <h:commandButton value="登录" actionListener="#{bangding.check2 }" action="#{bangding.check}"/>
      </h:form>
    </f:view>
    </body>
    </html>
    这样来,代码还看一些
      

  20.   

    这种问题 一个就是debug  再不就简单的 你在后台吧接收到的东西都输出 看哪个数据和预先的不一样  知道那么没接收到的   在看看配置 和参数什么的 是不是传错了
    一个空指针  卡好几天   。要是真工作了 咋办?
      

  21.   

    jsf和spring集成本来就容易出问题……话说,不建议新手用jsf(老手也不建议,jsf搞得太麻烦了)……
      

  22.   

    现在错误找到了,就是UserinfoBean中得到不了LoginService的借口。从spring中注入那部分不正确,请教一下,怎么写那个applicationContetext.xml和UserinfoBean中怎么获得接口,谢谢了
      

  23.   

    <bean id="LoginService" class="com.wgz.friend.LoginServiceimpl">
    你这个bean指向的都不是这个LoginService类