form提交
我想实现的功能是点击登录这张图片,实现表单提交到servlet中,在后台获得登录用户的信息后,返回到另一个页面。但是不知道为什么,怎么点击图片都无法实现表单提交。我的代码是这样的:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/basejsp.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台管理工作平台</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/css/style.css"/>
<script type="text/javascript" src="<%=path%>/js/common.js"></script>
<script language="javascript">
function changeCode(){
var codeImage = document.getElementById("codeImage");
var changeURL = "<%=path%>/jsp/common/image.jsp?date="+new Date()+"";
codeImage.src = changeURL;
}
//登录验证
function doSubmit(){
var account = document.getElementById("username").value;
if(account==""){
alert("用户名或者密码不能为空");
return;
}else if(document.getElementById("password").value==""){
alert("用户名或者密码不能为空");
return;
} else if(document.getElementById("code").value==""){
alert("验证码不能为空");
return;
}
document.getElementByIdName("login").submit();
}
}
//登陆页重填
function doReset(){
document.getElementByName("login").reset();
}
</script>
</head>
<body>
<div id="top"></div>
<form action="<%=path%>/servlet/AdminLoginServvlet?task=login" name="login" method="post">
<div id="center">
<div id="center_left"></div>
<div id="center_middle">
<div class="user">
<label>用户名:
<input type="text" name="username" id="username" />
</label>
</div>
<div class="user">
<label>密 码:
<input type="password" name="password" id="password" />
</label>
</div>
<div class="chknumber">
验证码:
<input name="code" type="text" id="code" maxlength="4" class="chknumber_input" />
<img src="<%=path%>/jsp/common/image.jsp" id="codeImage" onclick="changeCode();"/>
</div>
</div>
<div id="center_middle_right"></div>
<div id="errorArea">
<c:if test="${not empty operErr}">
<div id="operErr">${operErr}</div>
</c:if>
<%--错误信息从底层抛上来,然后在这边显示--%>
</div>
<div id="center_submit">
<div class="button" ><img src="<%=path%>/images/dl.gif" width="57" height="20" onclick="doSubmit()"/> </div>
<div class="button"> <img src="<%=path%>/images/cz.gif" width="57" height="20" onclick="doReset()";"/> </div>
</div>
<div id="center_right"></div>
</div>
</form>
<div id="footer"></div>
</body>
</html>