struts实现登录功能

一.使用struts2提供的表单标签来改造页面。

WebRoot/login/login.jsp
        
            <form>-------------------<s:form>
            <input type="text">------<s:textfield>
            <input type="password">---<s:password>
            <input type="submit">-----<s:submit>
            <input type="reset">------<s:reset>
           
            
            1.改造form

<s:form id="loginAction_home" name="form1" action="user_login" namespace="/" target="_parent" method="post">

 2.改造登录名

<s:textfield name="logonName" value="" id="logonName" cssClass="text" cssStyle="width: 160px;"/>

 3.改造登录密码
                <s:password  name="logonPwd" id="logonPwd" cssClass="text" cssStyle="width: 160px;"/>

密码框默认不回显示.需要设置属性showPassword="true"

 4.<s:submit name="submit" value="登录" cssClass="buttoninput"/>

         5.<s:reset name="reset" value="取消" cssClass="buttoninput"/>
            
            注意:struts2中的表单标签,有默认的主题xhtml.如果不想要添加任何修饰,只需要将主题修改为simple.
                1.全局
                    在struts.xml文件中配置一个常量
                    <constant name="struts.ui.theme" value="simple"></constant>
                2.局部
                    针对于某一个form.
                    <s:form theme="simple">
                3.局部

可以给任意的表单组件去指定theme属性值。

login.jsp:

<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript">
function ini(){document.form1.logonName.focus();
}
</script><html><head><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title></title><link href="${pageContext.request.contextPath}/css/Style.css" rel="stylesheet" type="text/css"></head><body onload="ini()"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><table width="452" height="290" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#FFFFFF"><table width="452" height="290" border="0" cellpadding="0" cellspacing="0"><tr><td height="74"><img src="${pageContext.request.contextPath}/images/logintitle.gif"></td></tr><tr><td align="center" valign="bottom" background="${pageContext.request.contextPath}/images/loginbg.gif"><s:form action="user_login" method="post" theme="simple" namespace="/" id="loginAction_home" name="form1" target="_top"><table border="0" align="center" cellpadding="2" cellspacing="0"><tr align="center"><td height="30" colspan="2" style="border-bottom: 1px dotted #cccccc"><strong style="font-size: 14px;">请登录</strong><!-- 错误信息回显 --><s:fielderror /> <s:actionerror/></td></tr><tr><td height="30" nowrap><font color="000F60"><strong>用户名:</strong> </font></td><td><s:textfield name="logonName" id="logonName" cssClass="text" cssStyle="width: 160px;"/></td></tr><tr><td height="30" nowrap><strong><font color="000F60">密码: </font> </strong></td><td><s:password name="logonPwd" id="logonPwd"  cssClass="text" cssStyle="width: 160px;" /></td></tr><tr><td height="30" nowrap colspan="2"><strong><font color="red"></font> </strong></td></tr><tr><td height="30"></td><td><input type="submit" name="submit" value="登陆" class="buttoninput"/><input type="reset" name="reset" value="取消" class="buttoninput"/></td></tr></table></s:form><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="30" align="center"></td></tr><tr><td height="23" align="center"></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body>
</html>

 二.需要使用xml配置方式对数据进行校验。
            用户名 非空,3-12位
            密码  非空

1.在UserAction所在包下创建一个UserAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE validators PUBLIC"-//Apache Struts//XWork Validator 1.0.3//EN""http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators><field name="logonName"><field-validator type="requiredstring"><message key="logonName.required"></message></field-validator><field-validator type="stringlength"><param name="minLength">3</param><param name="maxLength">12</param><message key="logonName.length"></message></field-validator></field><field name="logonPwd"><field-validator type="requiredstring"><message key="logonPwd.required"></message></field-validator></field>
</validators>         

 2.在xml文件中添加dtd约束

 <!DOCTYPE validators PUBLIC"-//Apache Struts//XWork Validator 1.0.3//EN""http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">

 3.对属性进行校验

  <field name="logonName"><field-validator type="requiredstring"><message>用户名不能为空</message></field-validator><field-validator type="stringlength"><param name="maxLength">12</param><param name="minLength">3</param><message>用户名长度必须在${minLength}到${maxLength}之间</message></field-validator></field><field name="logonPwd"><field-validator type="requiredstring"><message>密码不能为空</message></field-validator></field>在页面上通过<s:fielderror>

 3.登录成功,将用户存储到session,在页面上显示用户。

top.jsp   ${user.userName } 显示当前登陆用户

 /*** 员工登陆* * @return*/@InputConfig(resultName = "loginINPUT")// 修改workflow拦截器跳转视图public String login() {// 登陆数据 已经在 user中,传递业务层,查询UserService userService = new UserService();User logonUser = userService.login(user);// 判断是否登陆成功if (logonUser == null) {// 登陆失败this.addActionError(this.getText("loginfail"));return "loginINPUT";} else {// 登陆成功ServletActionContext.getRequest().getSession().setAttribute("user", logonUser);return "loginSUCCESS";}}

struts实战--登录功能实现相关推荐

  1. struts实战--添加功能(重点文件上传)

    struts实现添加功能(重点上传) 一.对add.jsp页面上html标签修改----struts2的表单标签 1.性别             原标签             <input ...

  2. springboot文件上传下载实战 —— 登录功能、展示所有文件

    springboot文件上传下载实战 创建项目 pom.xml 数据库建表与环境准备 建表SQL 配置文件 application.properties 整体架构 前端页面 登录页面 login.ht ...

  3. [Vue项目实战]登录功能实现

    登录功能实现 写在前面 登录概述 登录业务流程 登录业务的相关技术点 登录---token原理分析 登录功能实现 登录页面的布局 在components文件下创建一个vue文件 配置路由(并添加路由重 ...

  4. 06.简书项目实战三:详情页面和登录功能实现

    简书项目实战三:详情页面和登录功能实现 1. 详情页面布局 这部分的布局比之前的简单多了,就一个标题加上主要内容而已. export default class Detail extends Comp ...

  5. axure动态登录和html5,Axure8原型设计实战案例:如何实现登录功能?

    登录功能是一个非常常见的功能,几乎所有的产品都有登录功能,登录功能可以很简单,也可以非常复杂.我们在用axure做产品原型设计的时候,都会涉及到登录功能,那么,登录功能是怎么设计出来的呢? 本文和大家 ...

  6. 【struts2+hibernate+spring项目实战】实现用户登录功能(ssh)

    一.概述 从今天才开始有时间来总结总结以前自己练习的一些东西,希望总结出来对以后可以更加便捷的来学习,也希望可以帮助到正需要这些东西的同行人,一起学习,共同进步. 二. 登录功能总结 2.1.登录功能 ...

  7. ssm当用户登录成功显示用户名_从零到企业级SSM电商项目实战教程(十八)用户登录功能开发...

    用户模块功能介绍 1.登录 2.用户名验证 3.注册 4.忘记密码 5.提交问题答案 6.重置密码 7.获取用户信息 8.更新用户信息 9.退出登录 学习目标 1.理解横向越权.纵向越权安全漏洞 2. ...

  8. 3.1 Vue实战--电商后台管理系统 的登录功能 补充了 加密功能

    1. 原来功能的不足 当登录成功之后,打开调试面板,找到"网络",在请求体中会看到密码和用户名,这是不安全的.这是因为:http协议是明文传输,只要别人一抓包就可以获取到传输的报文 ...

  9. Axure8原型设计实战案例:如何实现登录功能和用户管理?8年专业产品经理设计分享

    8年专业产品经理,使用axure8,分享最常用的登录功能和用户管理设计,怎么设计出来的呢? 登录功能设计,是每位产品设计师必经之路,很好的学习和参考资料,作者原创不易.如果感觉不错,就点赞,评论和收藏 ...

最新文章

  1. 面试官:说说你对ZooKeeper集群与Leader选举的理解?
  2. Struts2后期(这框架目前正处于淘汰状态)
  3. 戴尔笔记本win8全新安装
  4. 简单聊聊AspNetCore的启动流程
  5. Sentinel(十)之系统自适应限流
  6. aws lambda_如何为AWS Lambda实施日志聚合
  7. 方法重载 java 1614780176
  8. 计算机用户里dell占c盘太多,我的本是戴尔,用的是Win732位旗舰版系统,C盘里面的用户总是爆满是为什么,求解...
  9. ACM-尼姆博弈之取(m堆)石子游戏——hdu2176
  10. python csv写入 不以科学计数法_【Python与GIS】聊聊Python与数据——上(三)
  11. 文本关键词提取算法总结
  12. thinkpad systemupdate 下载软件存放的位置
  13. 【环球产品探寻 4】Wolftech News拥有一流用户体验的媒体工作流系统 - 挪威
  14. python中对文件的操作总结
  15. 【金融财经】金融市场一周简报(2017-09-08)
  16. Hive的行列转换(行转多列、多列转行、行转单列、单列转行)
  17. sessionbean+entitybean 在 jbx+wl7中调试笔记。
  18. 【论文笔记】(VLDB 2020) A Benchmarking Study of Embedding-based Entity Alignment for Knowledge
  19. 5G 与 MEC 边缘计算
  20. 【QT】翻金币小游戏·我的学习版

热门文章

  1. JavaScript 读取、写入Txt文档
  2. IAR环境下STM32+IAP方案的实现(转)
  3. php 策略模式实现原理,php 策略模式原理与应用深入理解
  4. R语言:ts() 时间序列的建立
  5. 《研磨设计模式》chap20 享元模式 Flyweight (4)总结
  6. 密码技术--椭圆曲线算法EDCSA数字签名及Go语言应用
  7. 【漫天烟花】绚烂烟花点亮夜空也太美了叭、某程序员携带烟花秀给大家拜年啦~
  8. 强网杯2019 Copperstudy
  9. MySQL的主从复制主从同步
  10. 红帽杯——childRE