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)在线等解决方法,,,毕业设计要用,急,,,在线等谢谢
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)在线等解决方法,,,毕业设计要用,急,,,在线等谢谢
自己断点DEBUG去跟踪呀 空指针异常都是这么改的
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
就是不知道改怎么写,,,第一次自己写东西,卡好几天了,,,,求帮忙
<%@ 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>
运行到这个地方的时候,出现了错误,
你看看是怎么个情况
一开始看H。。我还以为什么来着的呢,建议你写html别名。。
action="#{userInfoBean.verify}"首先看看JSF的配置文件中有没有userInfoBean这个配置;
其次就是上面说的看看public String verify()方法能否执行到...
所以很可能是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";
}
}
private LoginService loginService;
private UserinfoService userinfoService;楼主可以尝试下,把这个两个service的get方法删掉,只保留set方式 试试看....
<property name="sessionFactory" ref="sessionFactory" />
</bean>
改成 loginService 再试试
<%@ 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>
这样来,代码还看一些
一个空指针 卡好几天 。要是真工作了 咋办?
你这个bean指向的都不是这个LoginService类