其他可能相关的配置和实现类如下:
<?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>
<form-beans >
<form-bean name="loginForm" type="ssh.struts.form.LoginForm" />
</form-beans>
<action-mappings >
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="suc" path="/success.jsp"></forward>
<forward name="fal" path="/login.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="ssh.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
======================================================================
Action 类
package ssh.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import ssh.dao.impl.StudentDaoImpl;
import ssh.struts.form.LoginForm;
public class LoginAction extends Action {
private StudentDaoImpl studentDaoImpl;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
String name=loginForm.getUsername();
String pwd=loginForm.getPassword();
String forward=null;
List list=studentDaoImpl.getStuByName(name);
if(list!=null){
if(pwd.equals("123")){
forward="suc";
}else{
ActionErrors errors=new ActionErrors();
errors.add("loginerror", new ActionMessage("error.login"));
forward="fal";
}
}
return mapping.findForward(forward);
}
public void setStudentDaoImpl(StudentDaoImpl studentDaoImpl) {
this.studentDaoImpl = studentDaoImpl;
}
}
=====================================================
DAO实现类
package ssh.dao.impl;
import java.util.List;
import org.hibernate.SessionFactory;
import ssh.dao.i.StudentDAO;
public class StudentDaoImpl implements StudentDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public List getStuByName(String name) { return this.sessionFactory.getCurrentSession().createQuery(
"from StudentInfo s where s.username=?").setParameter(0, name)
.list();
}}各位高手帮小弟看看不胜感激!!谢谢
<?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>
<form-beans >
<form-bean name="loginForm" type="ssh.struts.form.LoginForm" />
</form-beans>
<action-mappings >
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="suc" path="/success.jsp"></forward>
<forward name="fal" path="/login.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="ssh.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
======================================================================
Action 类
package ssh.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import ssh.dao.impl.StudentDaoImpl;
import ssh.struts.form.LoginForm;
public class LoginAction extends Action {
private StudentDaoImpl studentDaoImpl;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
String name=loginForm.getUsername();
String pwd=loginForm.getPassword();
String forward=null;
List list=studentDaoImpl.getStuByName(name);
if(list!=null){
if(pwd.equals("123")){
forward="suc";
}else{
ActionErrors errors=new ActionErrors();
errors.add("loginerror", new ActionMessage("error.login"));
forward="fal";
}
}
return mapping.findForward(forward);
}
public void setStudentDaoImpl(StudentDaoImpl studentDaoImpl) {
this.studentDaoImpl = studentDaoImpl;
}
}
=====================================================
DAO实现类
package ssh.dao.impl;
import java.util.List;
import org.hibernate.SessionFactory;
import ssh.dao.i.StudentDAO;
public class StudentDaoImpl implements StudentDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public List getStuByName(String name) { return this.sessionFactory.getCurrentSession().createQuery(
"from StudentInfo s where s.username=?").setParameter(0, name)
.list();
}}各位高手帮小弟看看不胜感激!!谢谢
解决方案 »
- 关于Java的一些基础问题(50分)
- Spring主要应学习什么内容
- Struts中创建ActionForm的异常
- struts中读xml文件时对xml文件有大小限制?
- hibernate中session.flush();这句起到什么作用?
- 谁有好的基于springjdbc的泛型dao,给大家分享下,项目中实际用的
- 诚心求问上线使用WEBLOGIC7的数据库连接池以后应该注意什么?
- 一个很不常见的问题 就不知道怎么下手
- 求在My Eclipse4.0和eclipse3.1平台上配置hibernate方法?
- JAVA解析XML的速度快吗?为什么我一个6M多的XML解析了20多分钟还没解析好
- 如何配置fckeditor上传文件类型
- 求救:createEntityManagerFactory-- NoClassDefFoundError: org/hibernate/proxy/EntityNotFoundDelegate
<list>
<value>ssh/model/StudentInfo.hbm.xml </value> </list>
</property>
这里有错:
<property name="mappingResources">
<list>
<value>StudentInfo.hbm.xml </value> </list>
</property> 你改下这里试试 我看了下你的代码,其他地方好像都没错
应该加包名ssh/model吧?
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager">
</property>
<property name="target">
.....
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED </prop>
</props>
</property>
因为这里的Hibernate是由spring管理的。