import java.net.*;
import java.lang.*;
import svc;
import java.util.*;
import java.io.IOException;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Logon extends HttpServlet {
static jdbcmysql MySql = new jdbcmysql();
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
URL url = new URL("http://1234.anotherServer.com/aaa");
String result = "NotPass";
svc svc = new svc(url);
_SoapPort sec = svc.get_SoapPort();
_xSoapPort _X = svc.get_xSoapPort();
Integer accessCount = new Integer(0);
String user_id = request.getParameter("id");
String password = request.getParameter("pw");
String _UserPassword = "'" + user_id + "[" + password + "]" + "'";
Long _t = new Long(0);
Long _timeout = new Long(0);
Long _now = new Long(System.currentTimeMillis() / 1000);
String _1 = "";
String _2 = "";
String _r = "";
String key = "";
Integer _rU = new Integer(13);
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager
.getConnection(
"jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF8",
"root", "root");
stmt = con.createStatement();
_2 = "select timeout from userlock where user=" + _UserPassword + ";";
rs = stmt.executeQuery(_2);
while (rs.next()) {
_r = _r + rs.getObject(1).toString();
}
_t = Long.parseLong(_r.trim());
con.close();
} catch (Exception e) {
e.printStackTrace();
}
if (_t>_now){result="Had Login,Cannot Login Again";}
else {
key = sec.logon(user_id, password);
result = (key.isEmpty()) ? "NotPass" : "Pass";
_1="1";
if (result.equals("Pass")) {
HttpSession session = request.getSession(true);
session.putValue("accessCount", accessCount);
session.putValue("user_id", user_id);
session.putValue("password", password);
session.putValue("key", key);
_1="2";
try {
_1="3";
_timeout = (Long) System.currentTimeMillis()/1000+120;
if (_t == 0) {
_1 = "insert into userlock (user,session,timeout) values ("+_UserPassword+",'"+key+"',"+_timeout+");";
MySql.createdbSQL = _1;
MySql.RunMySql();
}
else {
_1 = "UPDATE userlock set session='"+key+"',timeout="+_timeout+ " where user="+_UserPassword+";";
MySql.createdbSQL = _1;
MySql.RunMySql();
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} // EndElse (_t>_now)
StringBuilder sb = new StringBuilder();
sb.append("<message>");
sb.append(result);
sb.append("</message>");
response.setContentType("text/xml");
response.setCharacterEncoding("utf-8"); //utf8
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(sb.toString());
}
}
沒有留言:
張貼留言