An example of dynamic WAP website development with ASP technology

Source: Internet
Author: User
Tags error handling http request query reference version ticket client access
Dynamic

  section I: The potential of WAP

These days, we often hear about WAP technology, a technology of mobile internet. Technically, mobile phones are unlikely to compete with PCs, and mobile phone screens can accommodate very few characters, with limited bandwidth and clumsy typing. Then why do I have to introduce it, hey, here are two major I think WAP must have a success factor.

Everywhere:

As long as you have a mobile phone, you can access the WAP site everywhere.

Billing Organization:

In the near future, we will be able to through our mobile phone to pay for all our expenses, query a lot of information. We just have one more charge for our mobile phone, "WAP service charge".

So we can use the mobile phone to pay for our merchandise costs, credit cards are not, it will be able to become a new way of spending.

   section II: WAP Basics

WAP (Wireless application Protocol) v1.1 is an open specification that attempts to standardize mobile phone access to information and services. This specification is made up of
WAP Forum to develop, a civil organization. The 1.2-version WAP protocol will be considered the last WAP specification.

The basic concept of WAP is the reuse of Internet protocols, which must make it clear that WAP services are easily invoked on existing technologies.

The WAP protocol utilizes a layered structure that resembles our computer network. The lower levels are not much like our common web apps, but the top floor is still our old friend----HTTP.
The data is sent from the server, received from the server, the information can be stored on the server, the call can be CGI, or other methods, such as ASP.
It means that as long as you are an ASP, you can easily write your first WAP application.

Of course, in terms of cell phone bandwidth and user capabilities, mobile phones need different (more stringent) devices, so under current conditions, HTML can not adapt to WAP
The bandwidth available.

The location of WAP Forum is WML (Wireless mark-up Language), an XML-formatted language. WML is thin HTML.

WAP Forum also specifies the WMLScript, much like JavaScript, which is used only for mobile phones, which can handle client-side programs.

   section III: WML

Although I have explained the phone to the server communication, but the real client is not a mobile phone. A software (WAP gateway) actually Yundang the role. It
Convert a phone request to an HTTP request and return the server's response to the phone, and the WML file is compiled into a binary file by the WAP gateway at this time. Although some
WAP Geteway can convert HTML directly to WML, but don't expect them to arbitrarily convert HTML to anything we can read on the phone.

Of course, the emulator does not need a WAP gateway to work, it will download the WML file directly from the server (or open WML directly on the local machine) and display it
On the phone's screen. Figure One WAP structure

   WAP Emulator

In order to use WAP services, like our poor can not afford to buy a mobile phone, we need a WAP emulator. You can go to Nokia website to download a Nokia Toolkit
1.2, and you also have to install Java Virtual Machine 1.2.2, which can be downloaded from Sun Company for free, here is an example.

   WML Structure

A WML document is made up of plates, and a plate contains a lot of cards. In practice, you can think of a plate as a number of labels with names.
Html.

The mobile phone downloads a complete plate, but only one card can be displayed at a time. Browse through links to different places.

We're going to see a simple WML document, and you need to know some of the most basic XML.

below is a reference fragment:
<?xml version= "1.0"?> 

<! doctype wml public  "-//wapforum//dtd wml 1.1//en"   "http://www.wapforum.org/DTD/ Wml_1.1.xml "> 

<wml> 

<!-- root element --> 

<card id= "Card1"  title= "example 1" > 

<p> <!--  Cards can only support p and do blocks  --> 

<do type= "Accept"  label= "go to card 2" >  

<go href= "#card2"/> 

</do> 

this is the  first card. 

</p> 

</card> 

<card id= "Card2"  title= "example 1" > 

<p> 

this is the second  card. 

</p> 

</card> 

</wml> 

Once the phone receives the block, it displays the first card, and when you press the soft button on the left, you see the second card.

Section Fourth: Another way to book your movie tickets

In the previous section, I explained the most basic concepts of WAP and WML, and in this section we'll look at how ASP and WAP are combined.

Now in Oslo, cinemas provide a telephone system based on the sale of tickets, the system is very complex, and must give users some instructions to guide users to buy tickets, and users must find in the newspaper some kind of movie code, this is annoying, we introduce another method.

Here, this will show you a simple WAP application that allows mobile subscribers to book tickets: a service that is sure to be applauded. Users do not have to remember the annoying code, they can choose movies and cinemas directly from the menu, and users do not need authentication. In this example, users are required to pay 40 minutes before the movie starts, but in real life, users can also pay by phone.

This application imagines that a movie can be shown at multiple cinemas at the same time, and that a movie theater is staged at different times.

Here I do not think too much about the problem of error handling, because this is not the focus of this chapter, you like you can add yourself.

For simplicity, I used access 97来 as a database, and of course the real system won't use it, and other databases like SQL Server don't have to change much code.

  database Diagrams




   database Diagrams

. Movie and theater tables are clearly needed. The show table is used to track how many vacancies are still available for sale.

How to debug this program

In order to access this WAP service, you need a WAP emulator, which is mainly debugged on Nokia Toolkit 1.2, please check the previous section for details.

   Choose a movie

Select a movie in the list list:




Here is the code:

The following is a reference fragment:
<!--#include file=\ "conn.asp\"--><% ' send the right MIME type

Response.ContentType = \ "Text/vnd.wap.wml\"

The first thing to do is to declare WML, how the emulator doesn't declare XML in the right place, it doesn't accept WML although Nokia 7110 can ignore that, but it doesn't guarantee that other phones will do, so you have to do it. Also you have to set the MIME type well.

< XML version=\ "1.0\"? >

<! DOCTYPE WML public \ "-//wapforum//dtd WML 1.1//en\" \ http://www.wapforum.org/dtd/wml_1.1.xml\ >

< WML >

Before entering the next card there will be a flashing screen to display a picture wbmp a new format. This event is determined by the timer attribute, where we set the time to 5 seconds. The OnTimer event will take you to another card after it is raised. (WMBP's Photoshop plugin can be downloaded free from the Internet).

< card id=\ "splash\" ontimer=\ "#card1 \" title=\ "Welcome to\" > < timer value=\ "50\"/>

< P align=\ "Center\" >

< br/>

< img src=\ "pix/logo.wbmp\" alt=\ "WAP movies\"/>

</p >

</card >

< card id=\ "card1\" title=\ "Choose a film\" >

<%

SQLQuery = \ "SELECT [movie_id], [title] from movie\"

Set rsmovies = conn. Execute (SQLQuery)

:

% >

< p >

< select Name= ' movie ' >

<%

Do as not rsmovies.eof

Response.Write (\ "< option value= ' \" & Rsmovies (\ "movie_id\") & \ ">\" & Rsmovies (\ "title\") & \ "&l T /option >\ "& vbCrLf)

Rsmovies.movenext

Loop% >

</select >
This section is the focus of this article. Reading the required data from the database shows that as an ASP programmer, this is nothing special, but this simple program is now used for a new server. This also makes me think more about the network programming ASP in the WML commercial station than the Java servlet.

The following is a reference fragment:
< small > < anchor title=\ "Next!\" >next

< go href=\ "step2.asp\" method=\ "Get\" >

< Postfield name=\ "movie\" value=\ "$ (movie) \"/>

</go >

</anchor >

</small >

</p >



The submission of forms can also be done through soft switching functions (do and anchor). Here, I do this through a simple inline link, because I think it can make the user feel intuitive and friendly. Postfields is about the same as the hidden in HTML, but the WML variable does not need to be routed in JavaScript as it does in HTML, it can be written directly in WML, as explained in the previous section. The way to pass here is get, The Post method is also supported by the WAP specification, and the emulator can recognize it, but unfortunately, in Nokia 7110, this post is not supported, so you have no choice.


Choose movie theater and release time

This section of code allows the user to choose what time to watch the movie, and all the records are based on the movie selected on the previous page. Here to choose the cinema and the release time.

The following is a reference fragment:
movie_id = Request (\ "Movie\")
SQLQuery = \ "Select title from movie WHERE movie_id = \" & movie_id
Set Rsmovie = conn. Execute (SQLQuery)
Movie_title = Rsmovie (\ "Title\")
:
SQLQuery = \ "SELECT [Name], [TIME], [show_id] from show, theater \" &_
\ "WHERE show.movie_id = \" & movie_id &_
\ "and theater.theater_id = show.theater_id\"
Set rsshows = conn. Execute (SQLQuery)

If you study the code carefully, you will want to use the session to save the movie information, and then the query on this page is simpler. It is also unfortunate that the session requires the support of cookies, although it is also supported in the WAP specification, but is not supported in Nokia 7110, which means that we are not able to use the session in WAP services.

Here are some interesting things:

The following is a reference fragment:
< select Name= ' Show ' >
<%
Do as not rsshows.eof
Response.Write (\ "< option value= ' \" & Rsshows (\ "show_id\") & \ "' >\" & Left (Rsshows (\ "name\"), cutter) & "(\" & Rsshows (\ "time\") & \ ") \" & \ "</option >\" &vbcrlf)
Rsshows.movenext
Loop% >
</select >

If you're wondering about cutter variables, then there's something that makes you laugh and cry.

The following is a reference fragment:
Dim Cutter
If InStr (Request.ServerVariables (\ "http_user_agent\"), \ "Nokia7110\") Then
Cutter = 12
Else
Cutter = 7
End If

This code displays options based on different devices. We have plenty of reasons to do this, the Nokia toolit 1.2 emulator likes to cut off my options to only a few characters, and we want to show the movie name and release time so we have to reduce the character of the movie name. This is not a problem in a real cell phone, so we have to determine the type of device first.

Once I have the chance (flying knife I am very poor, no money, this is just a distant dream ...) Testing my code on real Nokia 7110, we immediately feel we have a bigger screen than we think. In fact, some cinemas have strange names, and these long names take up a lot of screen space, and we don't have to waste the display space and try to simplify those names.

The next step is to let the user select the number of votes they want. This part of the code is much like the other parts. I will query the same data from the database, because the session cannot be used on a real WAP phone, so I have to confirm some of the contents to see if there are any seats to sell.

The following is a reference fragment:
SQLQuery = \ "SELECT * from show WHERE show_id = \" & show_id
Set rsshow = conn. Execute (SQLQuery)
:
Seats = rsshow (\ "Free_seats\")
:
If seats = 0 Then
Response.Write (\ "Sorry, no More Seats\")
Rsshow.close
Set rsshow = Nothing
Response.Write (\ "</p ></card ></wml >\")
Response.End
Else
If seats > 6 Then ' book up to 6 tickets or Max available
Max_seats=6
Else
Max_seats = seats
End If
End If
% >
<%=movie_title% > at <% =theater_name% >
< select Name= ' ticket ' >
<%
Dim i
i = 1
Do While I < = Max_seats
Response.Write (\ "< option value= ' \" & I & \ "' >\" & I & \ "ticket (s) \" & \ "</option >\" & AMP;VBCRLF)
i = i + 1
Loop% >
</select >

  Number of votes stored

Now that we have all the data we need, we have to save them:

The following is a reference fragment:
Tickets = Request (\ "Ticket\")
:
Free_seats = Rsshow (\ "Free_seats\")
:
Free_seats = Free_seats-tickets
:
Sqlupdate = \ "UPDATE Show \" &_
\ "SET show.free_seats=\" & free_seats & \ "\" &_
\ "WHERE show_id=\" & show_id
Conn. Execute (Sqlupdate)
SQLQuery = \ "Select Max ([booking_id]) as Bookingnumber from booking\"
Set rsbooking = Conn.execute (sqlquery)
Maxbookid = rsbooking (\ "Bookingnumber\") + 1
Sqlinsert = \ "INSERT into booking (show_id, booked_seats) \" & _
\ VALUES (' & show_id & \ "', ' \" & Tickets & \ "') \"
Conn. Execute (sqlinsert)% >
Have booked <%=tickets% > ticket (s) for <%=movie_title% >< BR/>
The show'll take place at <%=theater_name% > (<%=time% >)
< br/>
Your Reference number is <%=maxbookid% >

Here is the display:

Figure 4: Complete the transaction.

The deal is finished and the cinema can collect money at the cinema gate.

  Conclusion

WAP is now just out of its first step, yet it is one of the most revolutionary it developments in recent years. In this article I introduced how to write WAP applications using ASP, and gave you some warning, hoping to be useful for your future development. Multimedia technology is still not too much for WAP, but its mobility is important, but also for businesses to provide a lot of business opportunities.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.