?
?这个代买是我在网上考下来的,调试了两周终于可以运行了。主要是太粗心了,而且总是沉不下去,不能认认真真的分析代码。希望大家吸取我的教训。
?
package com.user.action; import com.opensymphony.xwork2.ActionSupport; import com.user.dao.PersonManager; import com.user.vo.Person; public class LoginAction extends ActionSupport{ private String username; private String password; private PersonManager personManager; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public PersonManager getPersonManager() { return personManager; } public void setPersonManager(PersonManager personManager) { this.personManager = personManager; } @Override public String execute() throws Exception { String flag = ""; //PersonManager personManager = new PersonManager(); Person per = new Person(); per.setUname(this.username); per.setUpwd(this.password); if(personManager.isLogin(per)){ flag = "success"; } else{ flag = "fail"; } return flag; } }
?
package com.user.dao; import java.util.List; import org.hibernate.Query; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.user.vo.Person; public class PersonManager extends HibernateDaoSupport{ public boolean isLogin(Person per){ boolean flag = false; String hql = "From Person as p where p.uname=? and p.upwd=?"; Query q = this.getSession().createQuery(hql.toString()); q.setString(0, per.getUname()); q.setString(1, per.getUpwd()); List all = q.list(); if(all.size() > 0){ flag = true; } else{ flag = false; } return flag; } }
?
package com.user.vo; public class Person implements java.io.Serializable { private Integer id; private String uname; private String upwd; public Person() { } public Person(Integer id) { this.id = id; } public Person(Integer id, String uname, String upwd) { this.id = id; this.uname = uname; this.upwd = upwd; } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getUname() { return this.uname; } public void setUname(String uname) { this.uname = uname; } public String getUpwd() { return this.upwd; } public void setUpwd(String upwd) { this.upwd = upwd; } }
?
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.user.vo.Person" table="person" catalog="MAIN"> <id name="id" type="int"> <column name="id" length="4" /> </id> <property name="uname" type="java.lang.String"> <column name="uname" length="20" /> </property> <property name="upwd" type="java.lang.String"> <column name="upwd" length="20" /> </property> </class> </hibernate-mapping>
<?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.5.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="org.gjt.mm.mysql.Driver"> </property> <property name="url" value="jdbc:mysql://localhost:3306/test"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> <bean id="exampleHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.query.substitutions"> true 'T', false 'F' </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.c3p0.minPoolSize">5</prop> <prop key="hibernate.c3p0.maxPoolSize">20</prop> <prop key="hibernate.c3p0.timeout">600</prop> <prop key="hibernate.c3p0.max_statement">50</prop> <prop key="hibernate.c3p0.testConnectionOnCheckout"> false </prop> </props> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" destroy-method="destroy"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>com/user/vo/Person.hbm.xml</value></list> </property> </bean> <!-- sessionFactory配置 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> </props> </property> <property name="annotatedClasses"> <list> <value>edu.jxc.hr.model.SysUser</value> </list> </property> </bean> --> <!-- 配置PersonManager.java类文件 --> <bean id="personManager" class="com.user.dao.PersonManager"> <property name="sessionFactory" > <ref local="sessionFactory"/> </property> </bean> <!-- 配置LoginAction.java类文件 --> <bean id="loginAction" class="com.user.action.LoginAction" scope="singleton"> <property name="personManager"> <ref bean="personManager" /> </property> </bean> </beans>
?
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.objectFactory" value="spring"></constant> <!-- Rose India Struts 2 Tutorials --> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <!--导入struts-default.xml文件 --> <include file="struts-default.xml"></include> <!-- 配置中文支持 --> <constant name="struts.i18n.encoding" value="GBK"></constant> <!-- 配置Action --> <package name="struts" extends="struts-default" namespace="/"> <action name="login" class="loginAction"> <result name="success">/result.jsp</result> <result name="fail">/error.jsp</result> </action> </package> </struts>
??
<?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"> <!-- 配置spring的监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:Applicationcontext.xml</param-value> </context-param> <!-- 开启监听 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Struts2 配置 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app>
?
<%@ page language="java" contentType="text/HTML;charset=GBK" pageEncoding="GBK"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <center> <s:form action="login" method="POST" namespace="/"> <s:textfield name="username" label="用户名" size="14"/> <s:password name="password" label="密 码" size="14"/> <s:submit label="提交" /> </s:form> </center> </body> </html> error.jsp <%@ page language="java" contentType="text/HTML;charset=GBK" pageEncoding="GBK"%> <% out.println("输入用误,输入的信息为" + "</br>"); out.println("用户名: " + request.getParameter("username") + "</br>"); out.println("密 码: " + request.getParameter("password")); %> result.jsp <%@ page language="java" contentType="text/HTML;charset=GBK" pageEncoding="GBK"%> <% out.println("用户名是: " + request.getParameter("username") + "</br>"); out.println("密 码是: " + request.getParameter("password")); %>
?
1 楼
netbo
2010-11-25
有没有SSH 的?
2 楼
jiaonan
2010-11-27
额。。。。。好像有点麻烦了,另外最基础的框架不需要这么多架包,LZ的这些架包中有些架包是同一个架包,只是版本不同而已,最好只保留一个,免得引起冲突
3 楼
jjjssh
2010-11-28
嗯,记得当时刚搭s2sh框架时也花了挺多时间,主要是不知道取那个版本的包
我记得我的是struts2,spring2,hibernate3
我记得我的是struts2,spring2,hibernate3
4 楼
qkjava
2010-12-01
http://www.springside.org.cn/
5 楼
liukai
2010-12-09
我只需要10秒就能搭个springMVC框架
6 楼
riderarcher
2011-06-21
用eclipse的spring插件的吧