代码如下:
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*,com.maxcard.util.*"%>
<html>
<head>
<title> New Document </title>
</head>
<body>
<%
if(request.getHeader("Authorization") == null){
response.setStatus(401);
response.setHeader("WWW-authenticate","Basic realm=\"www.maxcard.com\"");
}else{
//取得输入的信息
String encoded=(request.getHeader("Authorization"));
//利用Base64作编码的转化
String up = StringUtil.decodeBase64(encoded);
String user="";
String password="";
if(up!=null){
//取出用户名和密码
user=up.substring(0,up.indexOf(":"));
password=up.substring(up.indexOf(":")+1);
}
if(user.equals("david")&&password.equals("maxcard")){
out.print("认证成功");
}else{
out.print("认证失败");
}
}
%>
</body>
</html>
相关工具包下载: http://www.bcxy.com/java/dbutil.htm