52,797
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.bean.*"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
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%>">
<script language="javascript" src="js/Script.js"></script>
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="#B1C2E9">
<%String s_username=request.getParameter("username");
String s_pwd=request.getParameter("pwd");
%>
<center><h1>管理员登陆</h1>
<form>
<table align="center" >
<tr>
<td align=right>用户名: </td>
<td><input name="username" type="text" id="username"/></td>
</tr>
<tr>
<td align=right>密 码 :</td>
<td><input name="pwd" type="text" id="pwd"/></td>
</tr>
<tr>
<td colspan=2></td>
</tr>
<tr>
<td align=center colspan=2>
<input type="submit" value="提交" onclick="javascript:logonSys(username.value,pwd.value)" name="submit"> //这里调用js中的响应函数
<input type="reset" value="重置" name="reset"></td>
</tr>
</table>
</form>
</center>
<br/>
</body>
</html>
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
if(xmlHttp.overrideMimeType){
xmlHttp.overrideMimeType('text/xml');
}
if(!xmlHttp)
alert("不能创建XMLHttpRequest对象");
}
function setQueryString(){
var param="";
for(var i=0;i<arguments.length;i++){
param+=arguments[i]+'='+encodeURI(arguments[i+1]);
if(i!=arguments.length-2){
param+="&";
i++;
}else{
break;
}
}
return param;
}
function goIndex(){
window.navigate("adminIndex.jsp")
}
function logonSys(username,pwd){
if(username==''){
alert('请输入用户姓名');
return;
}
if(pwd==''){
alert('请输入用户密码');
return;
}
login(username,pwd);
}
function login(username,pwd){
var param=setQueryString('username',username,'pwd',pwd);
createXMLHttpRequest();
xmlHttp.open('POST','CheckServlet',true);
xmlHttp.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=loginCallBack;
xmlHttp.send(param);
}
function loginCallBack(){
//alert(xmlHttp.readyState);
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var msg=xmlHttp.responseText;
alert(msg);
if(msg.indexOf('成功')!=-1) {
goIndex();
}
}
if(xmlHttp.status==500)
alert(xmlHttp.responseText);
}
}
package com.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.bean.*;
//这个servlet是为了处理登录时验证输入
public class CheckServlet extends HttpServlet {
//该段话是为了处理移植到不同平台时因JVM不同而造成的序列化问题
private static final long serialVersionUID = 1L;
public void Init() throws ServletException{
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
if(request.getParameter("username")!=null && request.getParameter("pwd")!=null){
String username=new String(request.getParameter("username")
.getBytes("ISO-8859-1"),"UTF-8");
String pwd=new String(request.getParameter("pwd")
.getBytes("ISO-8859-1"),"UTF-8");
DealBean db=new DealBean();
UserBean ub=db.checkManager(username, pwd);
request.getSession().setAttribute("user", ub);
db.Close();
if(ub==null)
out.print("您所输入的用户名或密码不正确");
else
out.print("登录成功");
}
else
out.print("您所输入的登录信息有误");
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
}