我搭建Java搭建SSH框架的时候报错总是报错'sessionFactory' or 'hibernateTemplate' is required,但是在applicationContext.xml中dao层添加了sessionFactory的注入了;实在不知道哪里错了,有人可以看一下吗?
applicationContext.xml:
package org.action;
import org.model.Student;
import org.service.StudentService;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.opensymphony.xwork2.ActionContext;
public class StudentAction extends HibernateDaoSupport{
private StudentService studentService;
private Student student;
public void setStudent(Student student) {
this.student = student;
}
//set注入
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
//添加学生
public String addStudent() throws Exception{
if(student.getSId()==null||"".equals(student.getSId())){
ActionContext.getContext().put("error", "输入账号有误");
return "error";
}
student.setPwd("123456");
//查找学号
//不存在
if( null != studentService.findById(student.getSId())){
studentService.save(student);
System.out.println("添加成功!");
return "addsuccess";
}
//存在
else{
ActionContext.getContext().put("error", "用户已存在!");
}
return "error";
}
}
StudentAction.java:
package org.action;
import org.model.Student;
import org.service.StudentService;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.opensymphony.xwork2.ActionContext;
public class StudentAction extends HibernateDaoSupport{
private StudentService studentService;
private Student student;
public void setStudent(Student student) {
this.student = student;
}
//set注入
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
//添加学生
public String addStudent() throws Exception{
if(student.getSId()==null||"".equals(student.getSId())){
ActionContext.getContext().put("error", "输入账号有误");
return "error";
}
student.setPwd("123456");
//查找学号
//不存在
if( null != studentService.findById(student.getSId())){
studentService.save(student);
System.out.println("添加成功!");
return "addsuccess";
}
//存在
else{
ActionContext.getContext().put("error", "用户已存在!");
}
return "error";
}
}
提交表单页面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!doctype html>
<html>
<head>
<title>添加学生信息</title>
</head>
<body>
<h3>
请填写学生信息
</h3>
<hr width="700" align="left">
<s:form action="addStudentAction" method="get" >
<table>
<tr>
<td>
<s:textfield name="student.SId" label="学号" value=""></s:textfield>
</td>
</tr>
<tr>
<td>
<s:textfield name="student.SName" label="姓名" value=""></s:textfield>
</td>
</tr>
<tr>
<td>
<s:radio name="student.sex" value="1" list="#{1:'男',0:'女'}" label="性别" />
</td>
</tr>
<tr>
<td>
<s:textfield name="student.age" label="年龄" value=""></s:textfield>
</td>
</tr>
<tr>
<td>
<s:textfield name="student.SSubject" label="专业" value=""></s:textfield>
</td>
</tr>
<tr>
<td>
<s:textfield name="student.tel" label="电话" value=""></s:textfield>
</td>
</tr>
<tr>
<td>
<s:textfield name="student.adddr" label="地址" value=""></s:textfield>
</td>
</tr>
</table>
<p>
<input type="submit" value="添加" />
<input type="reset" value="重置" />
</s:form>
</body>
</html>
structs.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<!-- 登录 -->
<action name="LoginAction" class="loginaction">
<result name="admin">admin/admin.jsp</result>
<result name="student">student/student.jsp</result>
<result name="teacher">teacher/teacher.jsp</result>
<result name="error">error.jsp</result>
</action>
<!-- 添加学生 -->
<action name="addStudentAction" class="studentaction" method = "addStudent">
</action>
</package>
</struts>