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.



在Servlet中,取得application有两种方法: 1.通过无参初始化方法,直接取得 public class Application extends HttpServlet {   ...
  • bugDemo
  • bugDemo
  • 2012年12月13日 22:25
  • 3709


Question: What is more advisable to create a thread, by implementing a Runnable interface or by exte...
  • tryonmind
  • tryonmind
  • 2007年05月26日 16:14
  • 905

JavaWeb ServletContext/application初试总结

简介:ServletContext/application 为什么将其两者放在一起介绍呢,因为他们可以被看做是同一个类,只是名字起得不同而已。 ServletContext是在Servle...
  • to_be_better
  • to_be_better
  • 2016年09月26日 18:46
  • 714

Tomcat's Java Servlet Examples Explained

Tomcat provides a number of excellent servlet examples in “\webapps\examples“. The servlet source fi...
  • gmemai
  • gmemai
  • 2015年08月31日 05:45
  • 345


WML的简单例子及编辑测试方法——欢迎访问天极软件WML教程专区  完成WAP服务器的建立和WAP浏览器的安装之后,我们接下来就可以使用WML语言来编写WAP网页或应用,并通过WAP服务器及浏览器进行...
  • yan_wang929
  • yan_wang929
  • 2007年02月09日 16:25
  • 756

解决使用tomcat7-maven-plugin插件时 “Application already exists at path”的问题

使用tomcat7-maven-plugin插件部署到tomcat服务器时,当服务器上已经有相同名字的项目就会导致 FAIL - Application already exists at path...
  • yhhazr
  • yhhazr
  • 2012年08月14日 20:12
  • 5389


对于移动终端,有时候服务器返回的是WML格式的页面。 比如说中国移动的一些需要使用cmwap接入点的业务页面(DCD, 移动梦网…), 这就要求终端浏览器必须能够支持对WML格式页面的解析和显示。 A...
  • centralperk
  • centralperk
  • 2012年05月02日 19:17
  • 4367

A Sample Of HQL And It's Application

 A Sample Of HQL And Its Applicationprivate String Rule(String str) {  if(str.length()==0)return "";...
  • Rachael1001
  • Rachael1001
  • 2007年04月19日 17:04
  • 771


Opera是直接支持wml的,但是有不少bug。 Firefox需要插件wmlbrowser来进行转换。 IE没法直接支持wml显示,但是有个在线转换的工具,通过中间代理的方式来获取内容,...
  • hq0927
  • hq0927
  • 2012年10月17日 10:32
  • 3386

Select a 'Java Application' launch configuration to use to create a runnable JAR.

Select a 'Java Application' launch configuration to use to create a runnable JAR.
  • cao812755156
  • cao812755156
  • 2015年08月04日 14:35
  • 1412
您举报文章:A Sample Servlet Application (WML, Java)