设为首页 加入收藏

TOP

SSH整合jar包分享及登陆实例详解(二)
2019-09-17 17:56:11 】 浏览:118
Tags:SSH 整合 jar 分享 登陆 实例 详解
oid
setUserService(UserService userService){ this.userService = userService; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public String login(){ this.user=userService.getUserByLoginname(username); if(user!=null&&user.getPassword().equals(password)){ //System.out.println("success"); ActionContext actionContext=ActionContext.getContext(); actionContext.getSession().put("user", user); this.checkresult = "ok"; }else{ this.checkresult ="err"; } return SUCCESS; } 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 String getcheckresult() { return this.checkresult; } }

 

struts.xml代码:
<package name="user" namespace="/" extends="json-default">
        <action name="login" class="loginAction" method="login">
            <result type="json">
                <param name="root">checkresult</param>
            </result>
        </action>   
</package>

以上已经完成表现层的设计,下面我们要具体的设计业务逻辑层和数据访问层,在这之前我们要先说明下各个文件的放置位置。

首先我们在包目录:com.标识公司名.项目名.模块名 

下再分别建sevice,dao,action,model四个包,service和dao中新建Impl放接口的实现,一个模块的包结构如下图。

applicationContent.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:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util" 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/util http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd"
        default-lazy-init ="true">
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
         <property name="sessionFactory" ref="sessionFactory" /> 
    </bean>    
     <!-- 启用事务注解扫描 -->
    <tx:annotation-driven transaction-manager=&quo
首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇程序员晋级CTO之路的8大准则 下一篇TCP的三次握手与四次挥手

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目