SSH整合问题 求高手解决
我用的是MyEclipse8.6+tomcat7
做的是struts2.1 + spring2.5 + hibernate3整合的小例子 ,用来练习。
添加的 所有支持均是myEclipse的可视化工具完成的。
login.jsp:
<form action="<%=request.getContextPath() %>/login.action">用户名:<input name="stu.stuName"><br>密码:<input name="stu.stuPwd"><br><input type="submit" value="submit"></form>
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> </web-app>
<?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="suibiaojiao" extends="struts-default"> <action name="login" class="loginAction"> <result name="ok">/ok.jsp</result> <result name="error">/error.jsp</result> </action> </package></struts>
<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"> </property> <property name="url" value="jdbc:mysql://127.0.0.1:3306"></property> <property name="username" value="root"></property> <property name="password" value="lm"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="studentDAO" class="com.lm.Impdao.StudentDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="loginAction" class="com.lm.struts2.loginAction"> <property name="stuDAO" ref="studentDAO"></property> </bean></beans>
<?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="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="show_sql">true</property> <mapping resource="com/lm/dao/Student.hbm.xml" /> </session-factory></hibernate-configuration>loginAction:[code=Java]package com.lm.struts2;import com.lm.Idao.IStudentDAO;import com.lm.dao.Student;import com.opensymphony.xwork2.ActionSupport;public class loginAction extends ActionSupport { private Student stu; private IStudentDAO stuDAO; public Student getStu() { return stu; } public IStudentDAO getStuDAO() { return stuDAO; } public void setStu(Student stu) { this.stu = stu; } public void setStuDAO(IStudentDAO stuDAO) { this.stuDAO = stuDAO; } public String execute() throws Exception{ String stuName = stu.getStuName(); String stuPwd = stu.getStuPwd(); String tag="error"; System.out.println(stuName+" "+stuPwd); if("a".equals(stuName) && "a".equals(stuPwd)) tag="ok"; //stuDAO.save(new Student(stuName,stuPwd)); return tag; }}