package members;
import push.Birthday;
import push.PushService;
import push.PushInitiator;
import push.User;
import feedback.Feedback;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.net.InetAddress;
import java.net.URL;
/**
* Members login
*
* @see HttpServlet
*/
public final class Members extends HttpServlet {
private static final String XML_VERSION = "<?xml version=\"1.0\"?>";
private static final String CONTENT_TYPE = "text/vnd.wap.wml";
private static final String DOC_TYPE = "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"\n"
+ " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
private static Connection con;
private static Statement stmt = null;
private static String membersFile = null;
private static final String HOME_PAGE = "/index.jsp";
private static final String ADMIN_NAME = "admin";
/* push initiator */
private static PushInitiator pusher = null;
/* push proxy gateway url */
private static String ppgUrl = null;
private static String authorization = null;
/* push services */
private static Vector pushServices = new Vector();
private static Birthday birthdayChecker = null;
private static PushService pushServiceServer = null;
private static String pushSupportFile = null;
private static String pushAddressType = null;
/**
* This is the initialization code that runs only once. The servlet is being
* placed into service.
*
* @exception ServletException
* if an error occurs
*/
public void init() throws ServletException {
String pushServiceStr = getInitParameter("pushservices");
StringTokenizer st = new StringTokenizer(pushServiceStr, ";");
String[] service;
while (st.hasMoreTokens()) {
try {
service = new String[2];
service[0] = st.nextToken().trim();
service[1] = st.nextToken().trim();
pushServices.add(service);
} catch (Exception e) {
System.err.println(e);
break;
}
}
// check, if proxy is set
boolean useProxy = new Boolean(getInitParameter("use-proxy"))
.booleanValue();
if (useProxy) {
// HTTP connections via a proxy server
String proxyHost = getInitParameter("proxy-host");
String proxyPort = getInitParameter("proxy-port");
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
}
try {
Class.forName(getInitParameter("dbdriver"));
con = DriverManager.getConnection(getInitParameter("database"),
getInitParameter("dbuser"),
getInitParameter("dbuserpasswd"));
stmt = con.createStatement();
try {
stmt
.executeUpdate("CREATE TABLE IF NOT EXISTS members (name VARCHAR(10) NOT NULL, passwd VARCHAR(10), dob VARCHAR(10), sex CHAR(1), email VARCHAR(30), phone VARCHAR(15), pushservices VARCHAR(20), PRIMARY KEY (name))");
} catch (SQLException e) {
System.err.println(e);
}
} catch (Exception ex) {
ex.printStackTrace();
}
/* Create a push initiator, used to initiate push messages */
ppgUrl = getInitParameter("ppg-url");
/* Some ppgs require authorization */
authorization = getInitParameter("authorization");
pushSupportFile = getInitParameter("pushsupport");
pushSupportFile = getServletContext().getRealPath(pushSupportFile);
/* Get push address type. It is either "IPv4" (default) or "PLMN". */
pushAddressType = getInitParameter("push-addresstype");
if (pushAddressType == null)
pushAddressType = "IPv4";
}
/**
* Called by the server to allow a servlet to handle a GET request.
*
* @param request
* a <code>HttpServletRequest</code> value
* @param response
* a <code>HttpServletResponse</code> value
* @exception ServletException
* if an error occurs
* @exception IOException
* if an error occurs
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* Called by the server to allow a servlet to handle a POST request.
*
* @param request
* a <code>HttpServletRequest</code> value
* @param response
* a <code>HttpServletResponse</code> value
* @exception ServletException
* if an error occurs
* @exception IOException
* if an error occurs
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
boolean cookiesCheck = request.getHeader("cookie") != null
&& request.isRequestedSessionIdValid();
final String jsessionID = cookiesCheck ? "" : ";jsessionid="
+ session.getId();
/*
* Request parameter "action" has one of the following values: - "login"
* - "new" - "checkin" - "change" - "delete" - "view" - "update" -
* "insert"
*/
String action = request.getParameter("action");
if (action == null)
action = "login"; // default action
String name = null;
String passwd = null;
String dob = null;
String sex = null;
String email = null;
String phone = null;
String pushservices = null;
if (action.equals("new") || action.equals("update")
|| action.equals("insert") || action.equals("checkin")) {
name = action.equals("update") ? (String) session
.getAttribute("name") : request.getParameter("name");
passwd = request.getParameter("passwd");
dob = request.getParameter("dob");
sex = request.getParameter("sex");
email = request.getParameter("email");
phone = request.getParameter("phone");
pushservices = request.getParameter("pushservices");
} else { // set values from the session attributes
name = (String) session.getAttribute("name");
passwd = (String) session.getAttribute("passwd");
dob = (String) session.getAttribute("dob");
sex = (String) session.getAttribute("sex");
email = (String) session.getAttribute("email");
phone = (String) session.getAttribute("phone");
pushservices = (String) session.getAttribute("pushservices");
}
// check if the client device supports WAP push */
boolean isPushSupported = pushSupported(request);
// assing a push-info object into session information of the user */
if (name != null) {
if (session.getAttribute("push-info") == null && isPushSupported)
session.setAttribute("push-info", new User(name, request
.getRemoteAddr()));
}
if (pusher == null) {
try {
URL contextRoot = new URL("http://" + request.getServerName()
+ ":" + request.getServerPort()
+ request.getContextPath() + "/");
pusher = new PushInitiator(new URL(contextRoot, ppgUrl),
authorization);
} catch (Exception e) {
System.err.println(e);
}
}
/*
* Create a members' birthday checker thread. A push message is sent
* when the birthday of a member is approaching
*/
if (birthdayChecker == null) {
birthdayChecker = new Birthday(pusher, "http://"
+ request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath() + HOME_PAGE, pushAddressType);
new Thread(birthdayChecker).start();
}
/*
* Create a push service server thread. The thread sends push messages
* to users. A user will receive push messages if he/she has selected
* any push services.
*/
if (pushServiceServer == null) {
pushServiceServer = new PushService(pusher, "http://"
+ request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath(), pushAddressType, 24);
new Thread(pushServiceServer).start();
}
// start generating the response ...
response.setContentType(CONTENT_TYPE);
// prevent caching of the response
response.setHeader("cache-control", "no-cache");
PrintWriter out = response.getWriter();
out.println(XML_VERSION);
out.println(DOC_TYPE);
out.println("<wml>");
out.println("<!-- provides a way back using the prev elemen
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
wappush.rar (41个子文件)
wappush
bin
members
Members.class 21KB
feedback
Feedback.class 9KB
web.xml 4KB
info
Info.class 10KB
Makefile.bat 146B
push
PushService.class 4KB
User.class 3KB
PushInitiator.class 6KB
PPG.class 8KB
Makefile 64B
Birthday.class 4KB
Winner.class 2KB
Recommendation.class 8KB
TestWappush.class 258B
Makefile 444B
commercials
Commercials.class 4KB
src
members
Members.java 25KB
feedback
Feedback.java 10KB
TestWappush.java 35B
web.xml 4KB
info
Info.java 10KB
Makefile.bat 146B
push
Winner.java 2KB
Birthday.java 3KB
User.java 4KB
PushService.java 3KB
PPG.java 10KB
Recommendation.java 8KB
Makefile 64B
PushInitiator.java 6KB
Makefile 444B
commercials
Commercials.java 4KB
.project 383B
index.jsp 3KB
.classpath 294B
web
newanimals.jsp 875B
discounts.jsp 554B
jokes.jsp 572B
news.jsp 503B
winner.jsp 728B
lib
servlet.jar 77KB
共 41 条
- 1
资源评论
JonSco
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功