`
doujiang327
  • 浏览: 66200 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

手工搭建注解方式的spring3+struts2.2+hibernate3.6+maven2

    博客分类:
  • ssh
阅读更多

      这段时间不是很忙,头给我说了个事儿:让我把公司的网站给整整,想起来公司好多技术都该换新版本了,这正好是个机会,于是就搭了一套最新的开发框架。

      IDE:myeclipse8.6

      JAR包管理:maven2

      spring版本:3.0.6.RELEASE

      (maven中央库目前不支持3.1.0)

      struts版本:2.2.3

      hibernate版本:3.6.8

 

 

      1.在myeclipse中新建一个maven工程:

         1.1 File-->New-->Other-->MyEclipse-->Maven-->Java Maven Project

         1.2 输入工程名、groupId、artifactId以及版本号

         1.3 在新建的工程中点右键-->Myeclipse-->Add Web Project Capabilities

               关于这种建工程的方式,有以下几点需要说明:

               1》我不知道在myeclipse如何直接建maven web工程,用maven自带的那个web工程插件建造不了,所以

                    就这么建了,知道怎么直接建的跟我说声,不过这样建有一个好处,就是可以部署到tomcat里面运行。

               2》不想用maven的我在下面贴出来jar包列表,你们可以自己下载。

       

         

       2.pom文件

         

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>baseFrameForMaven</groupId>
  <artifactId>baseFrameForMaven</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>baseFrameForMaven</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  	<!-- J2EE容器所需包 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    	<groupId>org.apache.openejb</groupId>
    	<artifactId>javaee-api</artifactId>
    	<version>5.0-1</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.faces</groupId>
    	<artifactId>jsf-api</artifactId>
    	<version>1.2_04</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>jstl</artifactId>
    	<version>1.2</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.servlet.jsp</groupId>
    	<artifactId>jsp-api</artifactId>
    	<version>2.1</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
    	<groupId>javax.faces</groupId>
    	<artifactId>jsf-impl</artifactId>
    	<version>1.2_04</version>
    	<scope>provided</scope>
    </dependency>
    <dependency>
  		<groupId>org.aspectj</groupId>
  		<artifactId>aspectjweaver</artifactId>
  		<version>1.6.12</version>
	</dependency>
	<!-- mysql数据库驱动 -->
	<dependency>
  		<groupId>mysql</groupId>
  		<artifactId>mysql-connector-java</artifactId>
  		<version>5.1.18</version>
	</dependency>
	<!-- c3p0数据库连接池 -->
	<dependency>
  		<groupId>c3p0</groupId>
  		<artifactId>c3p0</artifactId>
  		<version>0.9.1.2</version>
	</dependency>
	<!-- 这个包是我自己的,主要提供的一些通用hibernate方法,如果没有可以去掉 -->
	<dependency>
  		<groupId>cn.apple.erp</groupId>
  		<artifactId>erp_base</artifactId>
  		<version>1.0.0</version>
  		<exclusions>
  			<exclusion>
				<groupId>org.hibernate</groupId>
        		<artifactId>hibernate</artifactId>
			</exclusion>
			<exclusion>
				<groupId>proxool</groupId>
  		    	<artifactId>proxool</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
    <!-- ======================================================================= -->
    
    <!-- spring必须包 -->
    <!-- spring核心包 -->
    <dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-core</artifactId>
  		<version>3.0.6.RELEASE</version>
  		<!-- spring-asm-3.0.6.RELEASE.jar -->
  		<!-- commons-logging-1.1.1.jar -->
	</dependency>
	<!-- 利用IOC管理Bean的包 -->
    <dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-beans</artifactId>
  		<version>3.0.6.RELEASE</version>
	</dependency>
	<!-- 对bean再次封装后的包,方便性强。 -->
    <dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>3.0.6.RELEASE</version>
  		<!-- spring-expression-3.0.6.RELEASE.jar -->
  		<!-- spring-aop-3.0.6.RELEASE.jar -->
  		<!-- aopalliance-1.0.jar -->
	</dependency>
	
	<!-- spring扩展包 -->
	<!-- SpringWeb下的工具包 -->
    <dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-web</artifactId>
  		<version>3.0.6.RELEASE</version>
	</dependency>
	<!-- 对struts支持包 -->
	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-struts</artifactId>
  		<version>3.0.6.RELEASE</version>
  		<!-- spring-struts-3.0.6.RELEASE.jar -->
  		<!-- commons-validator-1.1.4.jar -->
  		<!-- commons-beanutils-1.7.0.jar -->
  		<!-- commons-digester-1.6.jar -->
  		<!-- oro-2.0.7.jar -->
  		<!-- spring-context-support-3.0.6.RELEASE.jar -->
  		<!-- struts-1.2.9.jar -->
  		<!-- spring-webmvc-3.0.6.RELEASE.jar -->
  		<!-- xalan-2.5.1.jar -->
	</dependency>
	<!-- 支持hibernate,对对象映射框架的支持 -->
    <dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-orm</artifactId>
  		<version>3.0.6.RELEASE</version>
  		<!-- spring-tx-3.0.6.RELEASE.jar -->
  		<!-- spring-jdbc-3.0.6.RELEASE.jar -->
	</dependency>
	<dependency>
  		<groupId>commons-dbcp</groupId>
  		<artifactId>commons-dbcp</artifactId>
  		<version>1.4</version>
	</dependency>
	<!-- ======================================================================= -->
	
	<!-- struts2.2.3必须包 -->
	<dependency>
  		<groupId>org.apache.struts</groupId>
  		<artifactId>struts2-core</artifactId>
  		<version>2.2.3.1</version>
  		<!-- ognl-3.0.1.jar -->
  		<!-- asm-commons-3.1.jar -->
  		<!-- asm-tree-3.1.jar -->
  		<!-- commons-lang-2.5.jar -->
  		<!-- commons-fileupload-1.2.2.jar -->
  		<!-- commons-io-2.0.1.jar -->
  		<!-- xwork-core-2.2.3.1.jar -->
  		<!-- javassist-3.11.0.GA.jar -->
  		<!-- freemarker-2.3.16.jar -->
	</dependency>
	<!-- 日志功能 -->
	<dependency>
  		<groupId>commons-logging</groupId>
  		<artifactId>commons-logging</artifactId>
  		<version>1.1</version>
  		<!-- avalon-framework-4.1.3.jar -->
  		<!-- servlet-api-2.3.jar -->
  		<!-- logkit-1.0.1.jar -->
  		<!-- log4j-1.2.12.jar -->
	</dependency>
	<!-- ASM字节码库 -->
	<dependency>
  		<groupId>asm</groupId>
  		<artifactId>asm</artifactId>
  		<version>3.1</version>
	</dependency>
	<!-- struts2对于spring的支持 -->
	<dependency>
  		<groupId>org.apache.struts</groupId>
  		<artifactId>struts2-spring-plugin</artifactId>
  		<version>2.2.3.1</version>
	</dependency>
	<!-- struts2中对于注解的支持 -->
	<dependency>
  		<groupId>org.apache.struts</groupId>
  		<artifactId>struts2-convention-plugin</artifactId>
  		<version>2.2.3.1</version>
	</dependency>
	
	
	<!-- hibernate3.6.8必须包 -->
	<!-- hibernate核心包 -->
	<dependency>
  		<groupId>org.hibernate</groupId>
  		<artifactId>hibernate-core</artifactId>
  		<version>3.6.8.Final</version>
  		<exclusions>
  			<exclusion>
				<groupId>commons-collections</groupId>
  		    	<artifactId>commons-collections</artifactId>
			</exclusion>
			<exclusion>
				<groupId>dom4j</groupId>
  		    	<artifactId>dom4j</artifactId>
			</exclusion>
			<exclusion>
				<groupId>org.slf4j</groupId>
  		    	<artifactId>slf4j-api</artifactId>
			</exclusion>
		</exclusions>
  		<!-- hibernate-commons-annotations-3.2.0.Final.jar1 -->
  		<!-- hibernate-jpa-2.0-api-1.0.1.Final.jar -->
  		<!-- jta-1.1.jar -->
	</dependency>
	<!-- hibernate使用的一个日志系统 -->
	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-api</artifactId>
  		<version>1.6.4</version>
	</dependency>
	<!-- 集合类 -->
	<dependency>
  		<groupId>commons-collections</groupId>
  		<artifactId>commons-collections</artifactId>
  		<version>3.2.1</version>
	</dependency>
	<!-- XML配置和映射管理器-->
	<dependency>
  		<groupId>dom4j</groupId>
  		<artifactId>dom4j</artifactId>
  		<version>1.6.1</version>
	</dependency>
	<!-- ASM字节码库-->
	<dependency>
  		<groupId>asm</groupId>
  		<artifactId>asm-attrs</artifactId>
  		<version>2.2.3</version>
	</dependency>
	<!-- cglib字节码解释器-->
	<dependency>
  		<groupId>cglib</groupId>
  		<artifactId>cglib-nodep</artifactId>
  		<version>2.2.2</version>
	</dependency>
  </dependencies>
</project>

 

 

 

      3. web.xml

     

<?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">
	
	<!-- log4j配置文件地址 -->
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:resources/log4j/log4j.properties</param-value>
	</context-param>
	
	<!-- 配置spring的配置文件 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:resources/spring/applicationContext.xml</param-value>
	</context-param>
  
	<!-- log4j监听 -->
	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	
	<!-- Open Session In View Filter -->
	<!-- Spring提供的一个针对Hibernate的一个支持类,
		发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束 -->
	<filter>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>singleSession</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- Spring监听 -->
  	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  	</listener>
  	
  	<!-- spring编码过滤器 -->
	<filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <!-- 强制进行转码 -->
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  
  	<!-- Struts2配置信息 -->
  	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
		<!-- 指定配置文件路径 -->
		<init-param>
			<param-name>config</param-name>
			<param-value>platform-web.xml,struts-default.xml,struts-plugin.xml,resources/struts/struts.xml</param-value>
		</init-param>
  	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
  	</filter-mapping>
  
  	<!-- 欢迎页面 -->
  	<welcome-file-list>
    	<welcome-file>/jsp/login/login.jsp</welcome-file>
  	</welcome-file-list>
</web-app>     

      

 

    4. log4j.properties

     

### set log levels ###
log4j.rootLogger = debug, stdout, D, E

### \u8f93\u51fa\u5230\u63a7\u5236\u53f0 ###
#kong zhi tai
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p] %m%n

### \u8f93\u51fa\u5230\u65e5\u5fd7\u6587\u4ef6 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ${webapp.root}/logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p] %m%n

### \u4fdd\u5b58\u5f02\u5e38\u4fe1\u606f\u5230\u5355\u72ec\u6587\u4ef6 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = ${webapp.root}/logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern =%-d{yyyy-MM-dd HH\:mm\:ss} [%t\:%r] - [%p] %m%n

 

 

 

    5. applicationContext.xml

   

<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<!-- 使用 annotation --> 
	<context:annotation-config />
	
	<!-- 使用 annotation 自动注册bean,并检查@Controller, @Service, @Repository注解已被注入 --> 
	<context:component-scan base-package="cn.apple.baseFrameForMaven.*" />
	
	<!-- hibernate属性配置 -->
	<context:property-placeholder location="classpath:resources/hibernate/hibernate.properties"/>
	
	<!-- hibernate 配置管理 -->
	<import resource="applicationContext-persistence.xml" />
	
</beans>

 

 

 

    6. applicationContext-persistence.xml

   

<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd">
	
	<!-- C3P0 数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${hibernate.connection.driver_class}"/> 
        <property name="jdbcUrl" value="${hibernate.connection.url}"/>
        <property name="properties"> 
            <props> 
                <prop key="user">${hibernate.connection.username}</prop>
                <prop key="password">${hibernate.connection.password}</prop>
            </props> 
        </property>
    </bean>
    
    <!-- 配置hibernate3相关属性 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="packagesToScan" value="cn.apple.baseFrameForMaven.model"/>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
				<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
				<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
				<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>	
				<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
			</props>
		</property>
	</bean>
	
	<!-- 配置事务管理 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<!-- 配置注解实现管理事务(cglib:proxy-target-class="true") -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

</beans>

 

 

 

    7. hibernate.properties

   

## hibernate
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.hbm2ddl.auto=update

## hibernate cache
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=true

## C3P0 configuration
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/baseframeformaven??useUnicode=true&characterEncoding=utf-8
hibernate.connection.username=root
hibernate.connection.password=123

 

 

 

    8. struts.xml

   

<?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.devMode" value="false" />
    <!-- 将对象交给spring管理 -->
    <constant name="struts.objectFactory" value="spring" />
    <!-- 指定资源编码类型 -->
    <constant name="struts.i18n.encoding" value="UTF-8" /> 
	<!-- 指定每次请求到达,重新加载资源文件 -->
    <constant name="struts.i18n.reload" value="false" />
    <!-- 指定每次配置文件更改后,自动重新加载 -->
    <constant name="struts.configuration.xml.reload" value="false" />
    <!-- 国际化资源文件 -->
    <constant name="struts.custom.i18n.resources" value="resources/content/Language" />
    <!-- 默认后缀名 -->
    <constant name="struts.action.extension" value="do,action,jhtml,," />
	<!-- Struts Annotation -->
    <constant name="actionPackages" value="cn.apple.baseFrameForMaven.action"/>
    
    <!-- 去掉struts2标签的自带样式 -->
    <constant name="struts.ui.theme" value="simple" /> 
	<constant name="struts.ui.templateDir" value="template" /> 
	<constant name="struts.ui.templateSuffix" value="ftl" />
</struts>

 

 

 

    9. Language_zh_CN.properties

   

Demo=\u793A\u4F8B

 

 

 

    10. Language_en_US.properties

   

Demo=Demo Page

 

 

    11. 如此这般,不出意外,你的程序就应该可以跑起来了,我写了一个简单的登录程序验证一下:

        login.jsp

       

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
  	<base href="<%=basePath%>">
    <title>基础框架--登录</title>
  </head>
  
  <body>
    <s:form action="loginAction">
    	<s:label value="%{#request.errorMessage}"/>
    	<s:textfield id="login" name="login" label="帐号" maxlength="36" size="20"/>
    	<s:password id="password" name="password" label="密码" maxlength="12" size="19"/>
    	<s:submit value="登陆" onclick="return validate()"/>
	</s:form>
  </body>
</html>

 

 

    success.jsp

   

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>基础框架--登录成功</title>
  </head>
  
  <body>
    	欢迎您:<s:label value="%{#request.userName}"/>
  </body>
</html>

 

 

 

   

package cn.apple.baseFrameForMaven.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import cn.apple.erp.base.action.BaseAction;
import cn.apple.baseFrameForMaven.model.User;
import cn.apple.baseFrameForMaven.service.UserService;

/**
 * 登录用ACTION
 * 
 * @author 张鑫
 *
 */
@Controller
public class LoginAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	@Resource
	private UserService userService;//用户信息service层

	/**
	 * 用户登录验证
	 * 
	 * @return 
	 */
	@SuppressWarnings("restriction")
	@Action(value = "/loginAction", 
			results = { @Result(name = ERROR, location = "/jsp/login/login.jsp"),
						@Result(name = SUCCESS, location = "/jsp/login/success.jsp")
					  })
	public String verification(){
		//从页面获取帐号和密码
		String login = httpServletRequest.getParameter("login");
		String password = httpServletRequest.getParameter("password");
		User user = userService.findUserByLogin(login);//根据帐号到数据库中获取用户信息
		
		//处理返回值信息
		if(user==null){ //没有该用户
			httpServletRequest.setAttribute("errorMessage", "该账户不存在");//设置出错提示信息
			return ERROR;
		}else if(user.getUser_password()==null){ //数据库该用户密码为空
			httpServletRequest.setAttribute("errorMessage", "帐号异常:没有密码。请联系管理员或者重新注册");//设置出错提示信息
			return ERROR;
		}else if(!(user.getUser_password().equals(password))){ //判断密码是否匹配
			httpServletRequest.setAttribute("errorMessage", "密码错误");//设置出错提示信息
			return ERROR;
		}else{ //登录成功,用户信息放入session
			httpServletRequest.setAttribute("userName", user.getUser_name());//设置用户名
			return SUCCESS;
		}
	}
}

 

 

    其他层我就不再往上写了。

分享到:
评论
6 楼 0101wangling 2013-03-28  
求份源码,搭建的时候总是说缺少驱动包,471267867@qq.com,速发,谢谢
5 楼 zongshoujin 2013-01-07  
在执行Add Web Project Capabilities时,web root directory怎么选择啊?请教!谢谢!qq:1211956756

4 楼 rantengfei1986 2012-12-11  
求源码,谢谢!419910472@qq.com
3 楼 jeffsui 2012-08-20  
源码更给一份吗?1795144310@qq.com
或者简单逻辑的,最好是注解方式!
2 楼 belialdehen 2012-07-26  
使用spring注解了吗?
1 楼 belialdehen 2012-07-26  
源码给一份呗,谢谢了2292991561@qq.com

相关推荐

    spring 3.0.4 +hibernate3.6+mybatis3.0.4+struts 2.1.8+freemark整合

    标题中的“spring 3.0.4 +hibernate3.6+mybatis3.0.4+struts 2.1.8+freemarker整合”提到了一个经典的Java Web开发框架组合,这个组合在早期非常流行,用于构建企业级应用。下面将详细介绍这些技术及其整合方式。 1...

    ssh整合配置(struts2.2.1+ hibernate3.6+spring3.0.5)

    SSH整合配置是Java Web开发中常见的一种框架集成方式,它涉及到Struts2、Hibernate和Spring三个核心组件。这些框架的组合使用,旨在提供一个高效、灵活且可维护的MVC(Model-View-Controller)应用架构。下面我们将...

    SSH框架的例子

    SSH框架是Java开发中常用的三大框架集成,包括Struts2、Spring和Hibernate。这个框架组合在企业级应用开发中有着广泛的应用,它们分别负责表现层、业务层和数据持久层的管理。 Struts2作为MVC(Model-View-...

    Spring in Action(第二版 中文高清版).part2

    A.2 把Spring添加为一个Maven 2依赖项 A.3 Spring与Ant A.4 Spring与Log4j 附录B 用(和不用)Spring进行测试 B.1 测试简介 B.1.1 理解不同类型的测试 B.1.2 使用JUnit B.1.3 Spring在测试中的角色 B.2 单元...

    Spring in Action(第2版)中文版

    a.2把spring添加为一个maven2依赖项 a.3spring与ant a.4spring与log4j 附录b用(和不用)spring进行测试 b.1测试简介 b.1.1理解不同类型的测试 b.1.2使用junit b.1.3spring在测试中的角色 b.2单元测试...

    Spring in Action(第二版 中文高清版).part1

    A.2 把Spring添加为一个Maven 2依赖项 A.3 Spring与Ant A.4 Spring与Log4j 附录B 用(和不用)Spring进行测试 B.1 测试简介 B.1.1 理解不同类型的测试 B.1.2 使用JUnit B.1.3 Spring在测试中的角色 B.2 单元...

    ssh(三大框架)集成

    ### SSH(Struts2, Spring, Hibernate)三大框架集成详解 #### 一、概述 SSH框架,即Struts2、Spring以及Hibernate三个框架的集成,是Java Web开发中非常流行的一种解决方案。它结合了MVC架构的优势,通过Struts2...

    spring官方文档

    它还可以与其他框架和技术结合使用,如Struts、Hibernate、EJB等。 #### 二、Spring框架依赖管理和命名约定 **2.1 依赖管理** - **Maven依赖管理**:Spring框架提供了一个“Bill Of Materials”(BOM)坐标,可以...

    Java学习笔记-个人整理的

    \contentsline {chapter}{Contents}{2}{section*.1} {1}Java基础}{17}{chapter.1} {1.1}基本语法}{17}{section.1.1} {1.2}数字表达方式}{17}{section.1.2} {1.3}补码}{19}{section.1.3} {1.3.1}总结}{23}{...

    2017年尚学堂Java培训课程大纲.docx

    - **Spring MVC注解开发**:学习基于注解的控制器开发方式。 - **处理器映射和处理器适配器**:掌握处理器映射和适配器的工作原理。 - **视图解析器、自定义视图的概念及应用**:了解视图解析器的作用,实现自定义...

Global site tag (gtag.js) - Google Analytics