自己做的一个登陆页面,struts2,spring,tomcat6.0 ,然而登陆页面每次登陆的时候,输入用户名和密码,点击登录,数据没有到后台,而是登陆页面重新刷新了一下,第二次再输入用户名和密码的时候就可以登陆进去了,问高手是什么原因
比较急,在线等待
比较急,在线等待
解决方案 »
- JSP页面里的java小脚本,只在页面刷新后才反应
- struts2+ajaxanhwhere 提示 AjaxAnyWhere error content-type in not text/xml[]
- Hibernate 无主键查询问题
- JSP传LIST
- struts+spring时,struts的action是单例的么?
- 在线等__求教JSP连接ACCESS数据库的问题___谢谢各位高手帮忙解答
- 如何处理网页察看HTML源文件和用java io流获取的源文件不同 急!!
- 郁闷,JSF竟然会有这种事.
- iframe的值为什么获取不了呢?请高手帮忙呀.
- 提交后返回的参数为什么是空值,"<>"里所有的东西都不见了。
- ssh框架中的struts2中的action出问题
- struts2 中 ServletActionContext.getPageContext()为什么总是获取为null值
<tr>
<td>
<font style="font-size: 14px;font-weight: bold;color: #116bbe;">用户名:</font>
</td>
<td>
<input type="text" size="30" height="20" width="80px"
id="userName" name="userName"/>
</td>
<td>
<span style="color: red">*</span>
<div
style="position: absolute; top: 462px; left: 785px; z-index: 9999; width: 120px">
<font color="red" style="font-size: 12px">${msg}</font>
</div>
</td>
</tr>
<tr>
<td>
<font style="font-size: 14px;font-weight: bold;color: #116bbe;">密 码:</font>
</td>
<td>
<input type="password" size="30" height="20" width="80px"
id="password" name="password"/>
</td>
<td>
<span style="color: red">*</span>
</td>
</tr>
<tr>
<input type="text" size="30" height="20" width="80px" id="userName" name="userName"/>
<input type="password" size="30" height="20" width="80px" id="password" name="password"/>
<input type="submit" value=".."/>
</form>
后台注意下userName password 的get set 方法
页面的提交那块的代码都没有,就给个table能看出什么?
还有action的处理方法也要贴出来。
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>系统登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<link href="App_Themes/system.css" rel="stylesheet" type="text/css" />
<link href="App_Themes/web.css" rel="stylesheet" type="text/css" />
<style>
body{
margin:0px auto;
padding:0px auto;
text-align:center;
}
input{
width:200px;
}
</style>
</head>
<script>
window.onload=function()
{
document.getElementById("userName").focus();
}
function myonSubmit()
{
if(document.getElementById('userName').value == null
|| document.getElementById('userName').value == "") {
alert('用户名不能为空');
return false;
}
if (document.getElementById('password').value == null || document.getElementById('password').value == "") {
alert('密码不能为空');
return false;
}
document.forms[0].submit();
}
</script>
<body>
<s:form action="userAction!doLogin.action" theme="simple"
method="post">
<div id="centerdiv">
<div id="main">
<div class="kj_left">
<img src="images/kj_logo.jpg" />
</div>
<div class="kj_left">
<img src="images/kj_top01.jpg" />
</div>
<div>
<img src="images/kj_top02.jpg" />
</div>
<div class="kj_left">
<img src="images/kj_left01.jpg" />
</div>
<div class="kj_center">
<div class="kj_dlbg">
<div class="kj_dlbk" align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<font style="font-size: 14px;font-weight: bold;color: #116bbe;">用户名:</font>
</td>
<td>
<input type="text" size="30" height="20" width="80px"
id="userName" name="userName"/>
</td>
<td>
<span style="color: red">*</span>
<div
style="position: absolute; top: 462px; left: 785px; z-index: 9999; width: 120px">
<font color="red" style="font-size: 12px">${msg}</font>
</div>
</td>
</tr>
<tr>
<td>
<font style="font-size: 14px;font-weight: bold;color: #116bbe;">密 码:</font>
</td>
<td>
<input type="password" size="30" height="20" width="80px"
id="password" name="password"/>
</td>
<td>
<span style="color: red">*</span>
</td>
</tr>
<tr>
<td colspan="2">
<div class="kj_dlk">
<div class="kj_dl">
<a href="javascript:myonSubmit()"><img src="images/kj_dl01.gif" />
</a>
</div>
<div class="kj_dl">
<a href="#"><img src="images/kj_dl02.gif" /> </a>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
<div>
<img src="images/kj_center01.jpg" />
</div>
</div>
<div class="kj_left">
<img src="images/kj_right01.jpg" />
</div>
</div>
</div>
</s:form>
</body>
</html>==================================================================================
HttpSession session = request.getSession();
session.removeAttribute("userInfo");
List list = userService.searchLonginUser(userMapping.getUserName(),
userMapping.getPassword());
if (CollectionUtils.isEmpty(list)) {
request.setAttribute("msg", "账号或者密码错误!");
return SUCCESS;
}
if (CollectionUtils.isNotEmpty(list)) {
UserMapping users = (UserMapping) list.get(0);
if (users.getFlag()!=null && users.getFlag() == 1) {
request.setAttribute("msg", "此用户已被禁用!");
return SUCCESS;
}
}
if (log.isInfoEnabled()) {
log.info("login successful");
}
session.setAttribute("userInfo", list.get(0));
getUserRole(request);
UserMapping user = (UserMapping) session.getAttribute("userInfo");
if (user != null) {
return "main";
} else {
return SUCCESS;
}
}
我的操作流程:
1:
打开页面,输入用户名和密码,点击登录,没有进 action ,页面只是刷新了一下,再重新输入登录,成功
2:
打开页面后,先刷新,再输入用户名密码,点击登录,成功
那个就必须把<a href="javascript:myonSubmit()"><img src="images/kj_dl01.gif" />
放到form外面
否则就这样写document.thisform.submit()
是某个角落里的拦截器惹的祸,判断session中有没有值,分我就平分给大家了