<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<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">
<%
String path = request.getContextPath();
%>
<link rel="stylesheet" href="<%=path%>/css/blj_style.css"
type="text/css" />
<title>Login</title>
<script type="text/javascript" charset="UTF-8"
src="<%=path%>/js/jquery.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var msgFlg = $("#msgId").val();
if(msgFlg=="error")
{
$("#usernameId").val($("#userId").val());
alert("用户名或密码错误,请重新输入");
$("#usernameId").focus();
$("#msgId").val("");
return false;
}
if ($("#usernameId").val() == "") {
$("#usernameId").focus();
return false;
}else{
alert("密码不能为空");
$("#passwordId").focus();
}
});
function CheckData(){
if(form.username.value==""){
window.alert("用户名错误");
$("#usernameId").focus();
return false;
}
function checkForm1()
{
$("#usernameId").val("");
$("#passwordId").val("");
return false;
};
};
</script>
</head>
<body>
<s:form action="LoginAction" namespace="/login" name="form" id="formId">
<s:hidden id="msgId" name="msgFlg"></s:hidden>
<s:hidden id="userId" name="%{#application.userName}"></s:hidden>
<table width="100%" height="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td height="600" align="center" valign="middle">
<table width="795" border="0" cellpadding="1" cellspacing="1"
bgcolor="#2c9cee">
<tr>
<td width="797" bgcolor="#FFFFFF">
<table width="795" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td colspan="2"><img src="<%=path%>/images/login_bg.jpg"
width="795" height="321" /></td>
</tr>
<tr>
<td width="565"><img src="<%=path%>/images/login_bg2.jpg"
width="565" height="141" /></td>
<td width="228" valign="top">
<table width="229" border="0" cellpadding="2" cellspacing="0"
class="txt">
<tr>
<td colspan="3" valign="top"><img
src="<%=path%>/images/login_conner.jpg" width="77" height="22" /></td>
</tr>
<tr height="1">
<td width="228" align="left" colspan="2"><s:textfield
name="username" label="用户名" id="usernameId"
cssStyle="width:145px;" /></td>
<td></td>
</tr>
<tr height="1">
<td width="228" align="left" colspan="2"><s:password
name="password" label="密 码" id="passwordId"
cssStyle="width:145px;" /></td>
<td></td>
</tr>
<tr>
<td align="right" colspan="2" height="8"><s:submit
value="登录" theme="simple" method="login" onclick="CheckData()"/>
<s:reset value="取消" theme="simple" /> </td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--<s:submit value="xml_ivtList" method="xml_ivtList"/>-->
<!--<s:submit value="xml_login" method="xml_login"/>-->
<!--<s:submit value="xml_newsList" method="xml_newsList"/>-->
</s:form>
</body>
</html>
前两天有个任务用struts2作登录页面,页面时很快就出来了,但是光标成了我的难点,在网上找了好多也没有整正确要么是密码错误的时候没法保存用户名,要么就是密码错误光标不停留在密码框内,最后还是在网上求助解决的,当我看到代码的时候特别感慨,也走了不少弯路,为了让也同样遇到这个问题的少走点弯路,特在此分享一下。 需要实现的功能:初始化的时候光标停留在用户名框内,密码错误,保存用户名,情况密码框光标停留在密码框内.......
转载于:https://my.oschina.net/yangxin540/blog/118011