<%@ page language = "java" import= "java.util.*"pageEncoding= "utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://" +request.getServerName()+":" +request.getServerPort()+path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01 Transitional//EN">
< html>
< head>
<base href = "<%= basePath%> " >
<title >My
JSP ‘login.jsp‘ starting page </title >
< script type= "text/javascript" src= "js/jquery-1.8.0.min.js" ></script >
<script type = "text/javascript">
function ajax_submit(){
varusername=document.getElementsByName( "username" )[0].value;
var password=document.getElementsByName( "password" )[0].value;
/* //一定要加入jquery.js
*/
$.ajax({
url: ‘${pageContext.request.contextPath
}/Userservlet?method=login‘,
type: ‘post‘,
data: ‘username=‘ +username+‘&password=‘ +password,
success: function (msg)
{
if ((msg=="error" ))
{
alert( "用户名或者密码错误!!" );
} else
if ((msg=="success" ))
window.location.href="${pageContext.request.contextPath}/main.jsp" ;
}
});
}
</ script>
</ head>
< body>
< div align= "center" style ="margin : auto;" >
<%-- <form action="" method="post">
--%>
<table >
<tr > 用户名: <input type = "text" name ="username" ></ tr> <br >
<tr > 密码:< input type ="password" name= "password" ></ tr> <br >
<tr > < input type= "submit" onclick ="ajax_submit()" value ="提交" ></ tr>
</table >
</ div>
</ body>
</ html>