?? windows.jsp
字號:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.security.*"%>
<%@ page import="java.net.*"%>
<%!
public static String byte2HEX(byte b) {
return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xF));
}
public static byte stringHEX2bytes(String str) {
return (byte) ("0123456789ABCDEF".indexOf(str.substring(0,1))*16 + "0123456789ABCDEF".indexOf(str.substring(1)));
}
public static String md5bytes2string(byte[] bytes){
String result = "";
for(int i=0; i<bytes.length; i++){
result += byte2HEX(bytes[i]);
}
return result;
}
public static byte[] md5string2bytes(String str){
byte[] b = new byte[str.length()/2];
for(int i=0; i<b.length; i++){
String s = str.substring(i*2,i*2+2);
b[i] = stringHEX2bytes(s);
}
return b;
}
/**
* 從response字符串中,取出key字段的值,如果key指定的字段不存在,返回null
* @param key -- 字段名稱
* @param response -- Time接口返回的內容。
* @return 字段的值,如果字段不存在返回null.
*/
public static String get(String key, String response)
{
String POSTFIX = "=\"";
String RIGTH_PARENTHESIS = "\"";
String field = key + POSTFIX;
String result = null;
if(response == null || response.trim().length() == 0)
{
return null;
}
if(response.indexOf(field) < 0)
{
return null;
}
int pre = response.indexOf(field) + field.length();
int post = response.indexOf(RIGTH_PARENTHESIS, pre);
if(post < 0)
{
return null;
}
result = response.substring(pre, post);
if(result != null && result.trim().length() == 0)
{
return null;
}
return result;
}
%>
<%
String userName = request.getParameter("username");
String password = request.getParameter("password");
String serviceCode = request.getParameter("serviceCode");
if(userName == null || userName.length()==0){
//初始頁面
%>
<html>
<head>
<title>
檢查用戶是否包月
</title>
</head>
<body>
檢查用戶是否正確,是否已包月
<form method="post" name="form1" action="windows.jsp">
用戶名 :<input name="username" type="text" value="icptest@GD.chinavnet.com"><BR>
密碼 :<input name="password" type="text" value="test"><BR>
服務代碼:<input name="serviceCode" type="text" value="45454"><BR>
<input type="submit" >
</form>
</body>
</html>
<%
}else {
MessageDigest aMD5Digest = MessageDigest.getInstance("MD5");
aMD5Digest.update(password.getBytes());
String md5edPass = md5bytes2string(aMD5Digest.digest());
//利用Object的hashCode生成隨機數
String challenge = new Object().hashCode()+"";
aMD5Digest.update((challenge + md5edPass).getBytes());
md5edPass = md5bytes2string(aMD5Digest.digest());
String serverURL="http://gd.chinavnet.com:8590/aaa/servlet/TimeInterface?user=" + userName + "&challenge=" + challenge + "&password="+md5edPass+"&serviceCode=" + serviceCode;
System.out.println(serverURL);
//invoke jsp pages here
URL aurl = new URL(serverURL);
BufferedReader in = new BufferedReader(new InputStreamReader(aurl.openStream()));
String body="";
String str=null;
while((str=in.readLine())!=null){
System.out.println(str);
body += str;
}
%>
服務器端返回結果:<BR>
result = <%=get("result",body)%><BR>
location = <%=get("location",body)%><BR>
password = <%=get("password",body)%><BR>
userType = <%=get("userType",body)%><BR>
billingMode = <%=get("billingMode",body)%><BR>
subscribeResult = <%=get("subscribeResult",body)%><BR>
<%
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -