A Sample Servlet Application (WML, Java)

转载 2005年03月02日 00:13:00
Techniques for sending WAP Push messages in batch and from database


Openwave WAP Push Library provides Java APIs that allow developers to send WAP Pushes to any WAP 1.2.1 compliant device. This technical note and companion servlet application describe how to manipulate a MySQL database using select, insert and update operations, and send WAP Pushes in batch to registered subscribers.

The sample application allows mobile phone users to register to receive offers from a ficticious online store that sells CDs and DVDs. The administrator of this store can send alerts to all subscribers when special offers and/or news becomes available by using a simple HTML form.

Download servletApplication.zip

The application is made up of three Java classes: registerWAP.java, sendPush.java, push.java, an HTML front end for sending alerts: alert.html, and two MySQL tables: user and alertText. The "user" table contains the following columns: subscriberID, host (gateway/up.link) name and user name. The alertText table contains a single column: alert text.

Note: this sample application is designed to send a WAP Push service indication. For details on how to send WAP Push in other content types, such as Service Load, or Cache Operation, please refer to WAP Push Developer Guide for more information.

Let's take a look at the Java classes that make up the backbone of this application:

registerWAP.java (used to get subscribers into the application)

registerWAP retrieves subscriberID, host name and user name from HTTP headers and querystring. Then it inserts these data to user table that is used to send WAP Push, and return the confirmation of registration to the user. The flow of the application is as follows:

Step 1: obtain subscriberID, host name (from HTTP headers), and user name that is input from a wml file and is passed to registerWAP.java on the query string. Here is the code that caputeres the data from within the servlet:

	String subno = request.getHeader("x-up-subno");
	String host = request.getHeader("x-up-uplink");
	String name = request.getParameter("first");

Step 2: make a database connection and insert subscriber ID, host name and user name to user table. Note that the driver and connection are based on mysql as the back end. This can be replaced with the appropriate JDBC driver for the for the database of your choice.

	String url = "jdbc:mysql://localhost:3306/copDB";
	Connection con = DriverManager.getConnection (url, "", ""); 
	Statement stmt = con.createStatement (); 
	stmt.executeUpdate("insert into user values('"+subno+"', '"+host+"','"+name+"')");

Step 3: send the confirmation in WML format back to the user.


alert.html provides an interface for the administrator to send WAP Push to all subscribers. It will allows the administrator to select the type of alter to be sent (Music or DVD), and this will be used for the alert title. It also allows the user to input text to be used in the WML deck that will be refered to when a user recieves and views the WAP Push. When the adminstrator submits the form, sendPush.java is called passing these data with post method.


sendPush sends a WAP Push (service indication) to all subscribers who have registered in the database. The flow of the application is as follows:

Step 1: retrieve alert title and text from POST data

Step 2: send a response in HTML format back to the browser

Step 3: store the alert text in alertText table for the further use

Step 4: retrieve all subscribers' information including subscriberID and host name from user table and send WAP Push in batch within a while loop. In this application, the key component is the method plSubmitMag() that implements the sending push task. The procedure for sending the alert is as follows:

  • Declare PPG URL, recipient address, push message ID, and SI URL. Since every push submission must have a unique identifier, a random number is assigned to the push message ID.
  • Instantiate the PPG object. Set the alert title caught by alert.html as the text to be displayed on the device when the alert is received.
  • Instantiate the service indication object and set the value of the href attribute that specifies the URI used to access the indicated service.
  • Set the action to signalHigh that instructs the PPG to present the alert as soon as possible.
  • Instantiate a plPushMessage object to build the push submission.
  • Instantiate a plQualityOfService object to set the quality of service to high and confirm always. As well set this object to the alert message.
  • Send the push submission to the PPG and instantiate an object to hold the response from the PPG.
  • The pertinent information returned from the PPG is printed on console.

push.java is pointed by SI URI. It makes a database connection and retrieves the alert text from alertText table. Then returns the alert text to the client device.




前言 Java语言 Java语言体系比较庞大,包括多个模块。从WEB项目应用角度讲有JSP、Servlet、JDBC、EJB四部分技术。其中还有其他的9个技术规范(JNDI,)  正文 Java ...

How to integrate Struts2 into Web Application and small sample//TODO Verify!!!

Maven: struts2的Login Sample  第一步,使用eclipse新建一个maven webapp工程,如下图所示:   点击next,选择webapp工程,然后...

Flex Store sample application - Flex Interface Guide (FIG): The Pan|Zoom component

User level Intermediate Most of the standard Flex data controls display con...

管理TAP端口并加入网桥 ----------intel dpdk 例子:Exception Path Sample Application

intel给的sample文档中关于Exception Path Sample Application例子的解释已经很清楚了,但是对于我这个刚刚接触网关知识的人来说还是有点陌生。 引用他们的图例:数...

Create Android Sample Application

  • 2013-12-05 13:33
  • 520KB
  • 下载

Java ThreadLocal - How to use and code sample

Source:http://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/ Thread Loc...