ssh整合--注册登录

用SSH实现登录注册

1、相关环境和技术:

  • IDE:eclipse
  • 数据库:MySQL,Navicat
  • 单元测试:JUnit
  • Struts2+Hibernate5+spring4

2、新建一个Dynamic Web project及搭建SSH环境
文件结构

3、数据库
数据库表结构

4、封装JavaBean和编写映射文件

    package hnt;
    public class Userinfo {
   
    private int id ;
    private String username;
    private String pwd;
    private String email;
    public Userinfo(){
    }
        public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
        public String toString() {
        return "Userinfo [id=" + id + ", username=" + username + ", pwd=" + pwd + ", email=" + email + "]";
    }
}

配置文件:Userinfo.hbm.xml

<hibernate-mapping>
    <class name="hnt.Userinfo" table="USERINFO">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="username" type="java.lang.String">
            <column name="USERNAME" />
        </property>
        <property name="pwd" type="java.lang.String">
            <column name="PWD" />
        </property>
        <property name="email" type="java.lang.String">
            <column name="EMAIL" />
        </property>      
    </class>
</hibernate-mapping>

———–由于hibernate交由Spring管理,所以不需要cfg.xml

web.xml

<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>
    <!-- 解决延迟加载的问题 -->
    <filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <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>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="crm" extends="struts-default" namespace="/">
<global-results>
<result name="login" type="redirect">/login.jsp</result>
</global-results>
<!-- 通配符配置--!>
<action name="user_*" class="userAction" method="{1}">  
        <resultname="loginok"type="redirect">/bookstore.jsp
        </result>
<allowed-methods>add,checkCode,login,exit</allowed-methods>     
        </action>
    </package>  
</struts>

5、Action

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值