- 浏览: 72904 次
- 性别:
- 来自: 临沂
文章分类
最新评论
-
yuanke:
呵呵,早就解决了!
JDIC做了一个IE浏览器 -
lzj0470:
兄弟,解决了吗?我这几天,也是遇到这样的问题。指定JRE,不能 ...
JDIC做了一个IE浏览器 -
yefansiping:
这个问题在3.0里面解决了,可是我的这块还是出现这样的问题了, ...
from提交的数据到后台是乱码 -
treblesoftware:
STRUTS2还是很好用,很简单的,把它有些鸡胁功能去掉之后, ...
学struts2有感 -
ranLoD:
恰巧我最痛恨的就是struts自带标签怎么办了,<s:f ...
学struts2有感
[color=blue]Exception:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NullPointerException
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
struts.action.LoginAction.execute(LoginAction.java:30)
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
这是spring配置文件:
<?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 id="cdao" class="dao.CustomerDao2">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean name="/login" class="struts.action.LoginAction">
<property name="cdao">
<ref local="cdao"/>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean></beans>
这是hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">MySql</property>
<property name="show_sql">true</property>
<mapping resource="po/Customer.hbm.xml" />
</session-factory>
</hibernate-configuration>
这是struts.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="cunKuanForm" type="struts.form.CunKuanForm" />
<form-bean name="loginForm" type="struts.form.LoginForm" />
<form-bean name="regForm" type="struts.form.RegForm" />
<form-bean name="quKuanForm" type="struts.form.QuKuanForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="cunKuanForm"
input="/cunKuan.jsp"
name="cunKuanForm"
path="/cunKuan"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="regForm"
input="/reg.jsp"
name="regForm"
path="/reg"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="quKuanForm"
input="/quKuan.jsp"
name="quKuanForm"
path="/quKuan"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action path="/logout" type="struts.action.LogoutAction" />
</action-mappings>
<message-resources parameter="struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
这是登陆LoginAction 的一部分:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import po.Customer;
import struts.form.LoginForm;
import dao.CustomerDao;
import dao.ICustomerDao;
public class LoginAction extends Action {
private ICustomerDao cdao;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
int account = loginForm.getAccount();
String password = loginForm.getPassword();
// Customer cus = new CustomerDao().getCustomerByAccount(account);
Customer cus = cdao.getCustomerByAccount(account);
if(cus==null || !cus.getPassword().equals(password)){//登陆不成功
return new ActionForward("/error.jsp");
}
request.getSession().setAttribute("cus", cus);
request.getSession().setAttribute("admin", "admin");
return new ActionForward("/ope.jsp");
}
public ICustomerDao getCdao() {
return cdao;
}
public void setCdao(ICustomerDao cdao) {
this.cdao = cdao;
}
}
这是ICustomerDao 接口:
package dao;
import po.Customer;
public interface ICustomerDao {
public abstract boolean insertCustomer(Customer cus);
public abstract boolean updateCustomer(Customer cus);
public abstract Customer getCustomerByAccount(int account);
}
这是hibernate 调用数据库的模板:
package dao;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import po.Customer;
public class CustomerDao2 extends HibernateDaoSupport implements ICustomerDao{
public Customer getCustomerByAccount(int account) {
return (Customer)this.getHibernateTemplate().get(Customer.class, account);
}
public boolean insertCustomer(Customer cus) {
return false;
}
public boolean updateCustomer(Customer cus) {
// TODO Auto-generated method stub
return false;
}
}
现在问题是用户一登陆,就报上面的异常,查了一天都没找出原因?[/color]
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NullPointerException
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
struts.action.LoginAction.execute(LoginAction.java:30)
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
这是spring配置文件:
<?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 id="cdao" class="dao.CustomerDao2">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean name="/login" class="struts.action.LoginAction">
<property name="cdao">
<ref local="cdao"/>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean></beans>
这是hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">MySql</property>
<property name="show_sql">true</property>
<mapping resource="po/Customer.hbm.xml" />
</session-factory>
</hibernate-configuration>
这是struts.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="cunKuanForm" type="struts.form.CunKuanForm" />
<form-bean name="loginForm" type="struts.form.LoginForm" />
<form-bean name="regForm" type="struts.form.RegForm" />
<form-bean name="quKuanForm" type="struts.form.QuKuanForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="cunKuanForm"
input="/cunKuan.jsp"
name="cunKuanForm"
path="/cunKuan"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="regForm"
input="/reg.jsp"
name="regForm"
path="/reg"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action
attribute="quKuanForm"
input="/quKuan.jsp"
name="quKuanForm"
path="/quKuan"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" />
<action path="/logout" type="struts.action.LogoutAction" />
</action-mappings>
<message-resources parameter="struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
这是登陆LoginAction 的一部分:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import po.Customer;
import struts.form.LoginForm;
import dao.CustomerDao;
import dao.ICustomerDao;
public class LoginAction extends Action {
private ICustomerDao cdao;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
int account = loginForm.getAccount();
String password = loginForm.getPassword();
// Customer cus = new CustomerDao().getCustomerByAccount(account);
Customer cus = cdao.getCustomerByAccount(account);
if(cus==null || !cus.getPassword().equals(password)){//登陆不成功
return new ActionForward("/error.jsp");
}
request.getSession().setAttribute("cus", cus);
request.getSession().setAttribute("admin", "admin");
return new ActionForward("/ope.jsp");
}
public ICustomerDao getCdao() {
return cdao;
}
public void setCdao(ICustomerDao cdao) {
this.cdao = cdao;
}
}
这是ICustomerDao 接口:
package dao;
import po.Customer;
public interface ICustomerDao {
public abstract boolean insertCustomer(Customer cus);
public abstract boolean updateCustomer(Customer cus);
public abstract Customer getCustomerByAccount(int account);
}
这是hibernate 调用数据库的模板:
package dao;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import po.Customer;
public class CustomerDao2 extends HibernateDaoSupport implements ICustomerDao{
public Customer getCustomerByAccount(int account) {
return (Customer)this.getHibernateTemplate().get(Customer.class, account);
}
public boolean insertCustomer(Customer cus) {
return false;
}
public boolean updateCustomer(Customer cus) {
// TODO Auto-generated method stub
return false;
}
}
现在问题是用户一登陆,就报上面的异常,查了一天都没找出原因?[/color]
评论
1 楼
yuanke
2008-09-10
dao如下:
public class UserDao{
HibernateTemplate ht;
SessionFactory sessionFactory ;
public void setSessionFactory(SessionFactory sessionFactory){
this.ht=new HibernateTemplate(sessionFactory);
}
}
就ok了无需继承HibernateDaoSupport
public class UserDao{
HibernateTemplate ht;
SessionFactory sessionFactory ;
public void setSessionFactory(SessionFactory sessionFactory){
this.ht=new HibernateTemplate(sessionFactory);
}
}
就ok了无需继承HibernateDaoSupport
发表评论
-
30分钟学会如何使用Shiro
2017-07-21 17:37 454本篇内容大多总结自张开涛的《跟我学Shiro》原文地址:ht ... -
Spring+Quartz实现定时从FTP服务器读取文件并存入Oracel数据库
2017-07-17 17:32 674... -
java收集邮箱
2013-10-24 12:51 647java收集群邮箱,首先登陆自己的QQ 然后直接访问:8403 ... -
谁能帮我看一下仿这个网站多少钱
2013-10-23 12:14 581最近挺无聊的,想弄个网站,谁能帮我看一下仿这个网站多少钱? w ... -
MyEclipse9.0正式版的破解和激活方法(注册机)
2013-06-13 12:46 10MyEclipse 9.0的到期了很头 ... -
网址导航代码
2013-02-24 21:04 901本代码是本人精心为网友准备的,热门网址导航站网罗精彩实用网址, ... -
html删除a标签并且替换网址
2013-01-09 17:06 1117做网站开发的时候,复制样式会产生网址,加入说我们想批量替换,下 ... -
filter过滤器的使用
2011-12-13 15:19 1106在jsp开发中,我们经常使用过滤器(filter)来过滤权 ... -
sa_framework,s2-tiger,s2-extension2.4 日文的api
2011-12-09 10:40 1104Seasar框架中常用的sa_framework,s2-t ... -
学struts2有感
2009-07-26 19:25 4231看到struts2.x,原以为是struts ... -
ejb中spring代理struts,action请求找不到,can not instance for path
2009-07-13 11:45 1549我在tomcat上struts集成spring没有问题, 但在 ... -
延迟加载 出问题了,有那位见过这个异常?
2009-04-08 17:18 2249我把 lazy 设 为 false 不行, 在web.x ... -
XLoadTree 基于AJAX + XML动态加载的JS树组件的文档
2009-04-08 10:39 2195最近 刚开始 树节点的加载,看了 一篇 文章不错,转转过来共享 ... -
strut2配置spring 用c3p0.ComboPooledDataSource 出现连接错误
2009-04-06 09:09 2045昨天 还可以了,今天 就不能连接了,报一下异常: HTTP S ... -
基于javaWEB学生管理系统需求分析
2009-03-11 19:53 1346这是我 做毕业设计的文档,包含 需求分析,结构设计,模块设计, ... -
JDIC做了一个IE浏览器
2008-09-19 17:04 3399有谁用过JDIC的,我们现在用JDIC做了一个IE浏览器,在E ... -
struts2 配置 exception求救
2008-08-16 10:38 2756我按要求配置,出现exception,没有找出来是什么原因,有 ... -
from提交的数据到后台是乱码
2008-08-13 16:55 3156请高手帮忙,在火狐浏览器插入中文没有问题,在遨游或IE就出现乱 ... -
ext 树状结构组成json格式
2008-08-05 09:41 3354public JSONArray loadOasys() { ... -
Ask help for lombox coonect to oracle10i
2008-04-27 07:23 1400当我配置好了后,还是报以下exception java.sq ...
相关推荐
return (Person) getHibernateTemplate().get(Person.class, new Integer(personId)); } } ``` 在这个例子中,`PersonDAOImpl`通过setter方法接收SessionFactory,并初始化HibernateTemplate。`getPersons()`方法...
return (Person) getHibernateTemplate().get(Person.class, personId); } // 保存或更新Person实例 public void savePerson(Person person) { getHibernateTemplate().saveOrUpdate(person); } // 删除...
return (Person) getHibernateTemplate().get(Person.class, new Integer(personId)); } // 保存或更新Person public void saveOrUpdatePerson(Person person) { getHibernateTemplate().saveOrUpdate(person)...
return (Person) getHibernateTemplate().get(Person.class, new Integer(personId)); } public void savePerson(Person person) { getHibernateTemplate().saveOrUpdate(person); } // 其他类似的方法... }...
02. `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 03. `name` varchar(45) NOT NULL, 04. `psw` varchar(45) NOT NULL, 05. PRIMARY KEY (`id`) 06.) 建好表后,生成实体类 [java] view ...
return null; } }); } } ``` - **HibernateDaoSupport**示例:`HibernateDaoSupport`同样支持编程式事务管理,但通常情况下会使用Hibernate自带的事务管理机制。 ```java public class TestA extends ...
return (PageSupport) getHibernateTemplate().execute( new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = cq....
12. return (Tfile) getHibernateTemplate().get(Tfile.class, fileId); 13. } 14. public void save(Tfile tfile) 15. { 16. getHibernateTemplate().save(tfile); 17. getHibernateTemplate().flush(); 18. } 19. ...
get() 方法一定要获取到真实的数据,否则返回 null。 5. Spring 事务 Spring 事务是指在 Spring 框架中对事务的支持。Spring 事务有多种方式,包括: * 声明事务 * 编程事务 Spring 事务的隔离级别包括: * ...
return ((Integer) list.get(0)).intValue(); } } ``` ##### 方法五:`getStartNum`方法 该方法用于计算每页的起始记录编号。 ```java public int getStartNum(int pageNum, int pageSize) { return (pageNum ...
Buy goods = (Buy) getHibernateTemplate().get(Buy.class, id); return goods; } } ``` #### 五、总结 本案例展示了如何使用Struts2框架构建一个简单的购物车系统。通过前端页面与后端逻辑的紧密结合,实现...
`load()`默认抛出`ObjectNotFoundException`异常,当实体不存在时,而`get()`方法则返回`null`。此外,`load()`仅在真正需要时才发出SQL查询,这称为懒加载,而`get()`方法则立即加载实体。 **7. Hibernate的缓存...
这些方法都通过调用`getHibernateTemplate().executeFind()`来执行具体的分页查询操作。 ##### 2. Dao接口定义 为了更好地组织代码,我们通常会定义一个DAO(Data Access Object)接口,用来规范数据访问层的行为...
- **get()**:立即加载实体,如果实体不存在则返回`null`。 #### 7. Hibernate中lazy loading的概念及openSessionInView模式 - **知识点概述**:Lazy Loading是一种延迟加载策略,而OpenSessionInView模式则是在...