登陆输入为空或错误时的提示信息
来源:互联网 发布:java测试工程师面试 编辑:程序博客网 时间:2024/06/05 15:34
<script type="text/javascript" src="./jQuery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="./jQuery/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="./jQuery/layer/layer.min.js"></script>
<script type="text/javascript">
function setNextFocus(str){
var keyCode = event.keyCode ? event.keyCode
: event.which ? event.which : event.charCode;
if(keyCode==13){
if(str=="account" && document.getElementById("account").value!=""){
document.getElementById("password").focus();
}else if(str=="password" && document.getElementById("password").value!=""){
login();
}
}
}
window.onload = function() {
$("#account").focus();
};
//点击登陆按钮提交前,判断是不是为空的
function login() {
var username = $("#account");
var password = $("#password");
var authcode = $("#authcode");
if (username.val() == null || username.val() == "") {
layer.msg("请输入用户名!", 2, 1);
layer.shift('top',500);
username.focus();
return false;
}
if (password.val() == null || password.val() == "") {
layer.msg("请输入密码!", 2, 1);
layer.shift('top',500);
password.focus();
return false;
}
if (authcode.val() == null || authcode.val() == "") {
layer.msg("请输入验证码!", 2, 1);
layer.shift('top',500);
password.focus();
return false;
}
$("#loginForm").submit();//如果都不为空就提交
}
<%--提示信息--%>//判断是不是错误的
<input type="hidden"id="tips" value="${tips}"/>
<c:if test="${flag==true}">
<script type="text/javascript">
layer.msg(decodeURI($("#tips").val()), 2, 1);
layer.shift('top',500);
</script>
</c:if>
<c:if test="${flag==false}">
<script type="text/javascript">
layer.msg(decodeURI($("#tips").val()), 2, 5);
layer.shift('top',500);
</script>
</c:if>
后台部分代码:
/**
* 用户登录
* @param account
* @param password
* @return
* @throws IOException
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public ModelAndView login(
@RequestParam(value = "account", required = false, defaultValue = "") String account,
@RequestParam(value = "password", required = false, defaultValue = "") String password,
@RequestParam(value = "authcode", required = false, defaultValue = "") String authcode,
HttpServletRequest request, HttpServletResponse response) throws IOException {
HashMap queryParams = new HashMap();
try {
account = EncodeFilter.encode(URLDecoder.decode(account, "utf-8"));
password = URLDecoder.decode(password, "utf-8");
authcode = EncodeFilter.encode(URLDecoder.decode(authcode, "utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
queryParams.put("account", account);
if (!account.equals("")) {
User user = userService.findUser(queryParams);
if (user != null) {
String currPass = SecurityUtil.EncryptECB(Constant.SECURITY_KEY, password);
if (currPass.equals(user.getPassword())) {
String authcodes=(String) request.getSession().getAttribute("rand");
//toLowerCase大写转换为小写
if(authcode.toLowerCase().equals(authcodes.toLowerCase())){
logger.info("user " + user.getAccount() + " login");
// 设置权限和菜单
setOperAndMenu(user);
request.getSession().setAttribute("user",user);
SessionUtils.saveLoginUser(account);// 做个标记
SessionUtils.saveSessionAttribute(Constant.USER, user);
// 查询所有的菜单信息
SessionUtils.saveSessionAttribute(Constant.MENUS, userService.queryMenu(null));
/*SessionUtils.saveSessionAttribute(ADDV,informationService.getAddv());
SessionUtils.saveSessionAttribute(VALLEY,informationService.getValley());
SessionUtils.saveSessionAttribute(PROJECT_TYPE,informationService.getProjectType());
SessionUtils.saveSessionAttribute(PROJECT_GRADE,informationService.getProjectGrade());
SessionUtils.saveSessionAttribute(MANAGE_COM,informationService.getManageCom());
SessionUtils.saveSessionAttribute(PROJECT_NAME,informationService.getProjectName());*/
return new ModelAndView("main",null);
}else{
queryParams.put("tips", URLEncoder.encode("验证码错误!","utf-8"));
queryParams.put("flag",false);
return new ModelAndView("login",queryParams);
}
} else {
queryParams.put("tips", "密码错误!");
queryParams.put("flag", false);
return new ModelAndView("login", queryParams);
}
} else {
logger.info("user " + account + " not exists");
queryParams.put("tips", "用户名" + account + "不存在!");
queryParams.put("flag",false);
return new ModelAndView("login",queryParams);
}
} else {
return new ModelAndView(new RedirectView("index.do"), queryParams);
}
}
/**
* 生成随机颜色
*/
private Color getRandColor(int fc, int bc) {
Random random = new Random();
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
/**
* 用户注销
* @throws UnsupportedEncodingException
*
*/
@RequestMapping(value="logout")
public ModelAndView logout() throws UnsupportedEncodingException{
SessionUtils.removeSessionAllAttribute();
Map<String, Object> model = new HashMap<String, Object>();
model.put("flag",true);
model.put("tips", URLEncoder.encode("您已成功退出系统。","utf-8"));
return new ModelAndView("login", model);
}
/**
* url过滤
* @return
*/
@RequestMapping(value = "index")
public ModelAndView index() {
return new ModelAndView("login");
}
login.jsp部分代码:
<table style="margin:0 auto; border-collapse:collapse; width:100%;">
<tr>
<td style="background:url(./images/back_left.jpg); padding:0;"> </td>
<td style="width:1278px; padding:0;">
<table style="width:1278px; height:764px; margin:0 auto; border-collapse:collapse; background:url(./images/login_shadow.jpg);font-size: 40px; color: #FFF;">
<tr>
<td height="68" colspan="3" align="center"><span class="header"><img src="./images/logo.png" width="60" height="62" alt="psxq">深圳市坪山新区水务及三防信息化系统</span></td>
</tr>
<tr>
<td width="248" height="561"> </td>
<td width="765" height="561" align="center" valign="middle"><div id="logdiv">
<form id="loginForm" action="./login.do" method="post">
<table style="width:397px; height:160px; font-size: 14px; color: #264EBD; font-family: Arial, Helvetica, sans-serif;">
<tr height="80">
<td width="68"> </td>
<td width="89"> </td>
<td><span style="color:red;font-size:12px;"></span> </td>
</tr>
<tr>
<td> </td>
<td align="right">用户名:</td>
<td><label for="account"></label> <input
name="account" type="text" id="account" maxlength='24' style="width:160px;hight:18px;vertical-align:middle;" onKeyPress="setNextFocus(this.id);"/></td>
</tr>
<tr>
<td> </td>
<td align="right">密 码:</td>
<td><label for="password"></label> <input name="password" maxlength='24' type="password" id="password"
style="width:160px;hight:18px;vertical-align:middle;" onKeyPress="setNextFocus(this.id);"/></td>
</tr>
<tr>
<td> </td>
<td align="right">验证码:</td>
<td ><label for="authcode"></label>
<input name="authcode" type="text" id="authcode" maxlength='4' style="width:90px;hight:20px;vertical-align:middle;" onKeyPress="setNextFocus(this.id);"/>
<img alt="验证码" style="width:65px;hight:18px;vertical-align:middle;" id="imagecode" src="<%=request.getContextPath() %>/servlet/ImageServlet"/>
<a href="javascript: reloadCode();" style="color:#264EBD;">看不清楚</a>
</tr>
</table>
<div
style="width: 240px; height: 50px; margin-left: 20px; margin-top: 40px;">
<div
style="margin: 3px; width: 80px; height: 40px; display: inline-block; cursor: pointer;"
onclick="login();"></div>
<div style="display: inline-block; width: 40px;"></div>
<div
style="margin: 3px; width: 80px; height: 40px; display: inline-block; cursor: pointer;"
onclick="loginForm.reset();"></div>
</div>
</form>
</div></td>
<td width="267" height="561"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3" align="center"><br /> <span class="copyright">CopyRight
© 2001 - 2013 深圳市路路通网络通信有限公司</span> </td>
</tr>
</table>
</td>
<td background="./images/background.jpg"> </td>
</tr>
</table>
- 登陆输入为空或错误时的提示信息
- 判断输入的信息是否为空,如果为空,提示信息
- 错误提示“为空或不是对象”的解决方法
- 出现JS错误提示null为空或不是对象的错误
- Android ClearEditText:输入用户名、密码错误时整体删除及输入为空时候晃动提示
- Android ClearEditText:输入用户名、密码错误时整体删除及输入为空时候晃动提示
- Android ClearEditText:输入用户名、密码错误时整体删除及输入为空时候晃动提示
- 登陆注册密码错误或者输入为空时震动效果
- 实现用户登录时若没有输入用户名,给出用户名不能为空的提示,若没有输入密码,给出密码不能为空的提示
- sqlserver登陆后报不能为空的错误
- 检查表或字段的描述信息是否为空
- datalist 绑定数据为空时,显示提示信息
- #学习笔记#(4)输入框提示信息不能为空--JavaScript改变CSS样式
- 关于 '_EVENTTARGET'为空或不是对象 的奇怪错误
- 检查输入是否为空并提示
- 提示:id为空或不是对象
- 判断输入信息是否为空
- 登陆域时提示:指定域的名称或安全标识SID与该域的信任信息不一致
- JAVA细粒度锁实现的几种方式
- 五大常用算法——分治法,动态规划,回溯法,分支界限法,贪心算法
- 一行代码实现 按钮的选中与反选
- 获取今天凌晨和今天最后时刻
- 他人AS项目导入自己AS中的替换方法
- 登陆输入为空或错误时的提示信息
- String、StringBuffer与StringBuilder之间区别
- Bom和Dom的基本使用
- Java中的数组和方法
- solr 的commit, soft commit等
- win7下安装 Ubuntu双系统(直接硬盘安装)错误问题完美解决,卡屏,无法启动
- log4j按不同级别输出到日志文件
- BottomSheet
- openwrt STA+AP共存模式