WAP website development instance

Source: Internet
Author: User
In fact, most of WAP development and general web development are the same. The server-side processing code is basically the same, but it is different in the output to the browser, generally, the Web is the HTML and JavaScript code output, while the WAP outputs WML and WMLScript. Therefore, the technology used to develop the web is also suitable for the development of WAP sites. Here we recommend a browser-opera, which can not only browse Web sites, but also WAP sites.
The following is an online document for beginners.

Section 1: Potential of WAP

These days, we often hear about WAP Technology, a mobile Internet technology. Technically speaking, mobile phones cannot compete with PCs. Mobile phone screens can only contain a few characters, and their bandwidth is also very limited and the input is clumsy. So why should I introduce it? hey, there are two main reasons I think WAP must be successful.

Ubiquitous:

If you have a mobile phone, you can access the WAP website wherever you go.

Billing organization:

In the near future, we will be able to use our mobile phones to pay for all our fees and query a lot of information. We only pay an additional fee for the Mobile Phone Fee "WAP service fee ".

In this way, we can use our mobile phones to pay for our products, and credit cards are not used. It will surely become a new way of consumption.

  Section 2: WAP Basics

WAP (Wireless Application Protocol) V1.1 is an open specification that attempts to regulate the mobile phone access information and service industry. This specification is based on
A civil organization developed by WAP Forum. Version 1.2 of the WAP protocol will be considered as the final WAP specification.

The most basic concept of WAP is to reuse the Internet protocol, which must be clearly and easily invoked in the existing technology.

WAP uses a layered structure similar to our computer network. The lower level is not like our common web applications, but the top layer is our old friend-HTTP.
Data is sent from the server and received from the server. The information can be stored on the server, and CGI or other methods may be used for calling, such as ASP.
It means that as long as you have ASP, you can easily write your first WAP application.

Of course, in terms of the bandwidth and user capabilities of mobile phones, mobile phones need different (more stringent) devices, so HTML cannot adapt to the limitations of WAP under current conditions.
Bandwidth.

WAP Forum is positioned as WML (Wireless mark-up language), an XML format language. WML is a simplified HTML.

WAP Forum also specifies WMLScript, which is similar to JavaScript and only used for mobile phones. It can process client programs.

  Section 3: WML

Although I have already explained the communication between the mobile phone and the server, the real client is not a mobile phone. A software (WAP Gateway) actually allows this role. It
Convert the mobile phone request to an HTTP request, and return the server response to the mobile phone. The WML file is compiled into a binary file by the WAP Gateway. Although some
WAP geteway can directly convert HTML into WML, but do not expect them to convert HTML into something we can understand on mobile phones.

Of course, the simulator does not need a WAP gateway to work. It will directly download the WML file from the server (or directly open WML on the local machine) and display it
On the phone screen. Figure 1 WAP Structure

  WAP Simulator

In order to use the WAP Service, a WAP simulator is required for poor people like ours who cannot afford a mobile phone. You can download a Nokia toolkit from Nokia website.
1.2. You also need to install Java Virtual Machine 1.2.2, which can be downloaded from sun for free. Here is an example.

  WML Structure

A WML document is composed of sections and contains many cards. In reality, you can think of a section as composed of many named labels.
HTML.

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

We will see a simple WML document. You must understand the most basic XML.

The following is a reference clip:
<? XML version = "1.0"?>

<! Doctype WML public "-// wapforum // dtd wml 1.1 //" 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 this block, it will display the first card. When you press the soft key on the left, you will see the second card.

Section 4: another method for booking your movie tickets

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

Now in Oslo, cinemas provide a telephone-based system to sell tickets. This system is complex and requires instructions to guide users to buy tickets, in addition, the user must find the code for a certain movie in the newspaper. This is annoying. Let's introduce another method.

Here, we will show you a simple WAP application that allows mobile phone users to book tickets: a service that is definitely amazing. Users do not have to remember the annoying code. They can directly select movies and cinemas from the menu, and users do not need to authenticate. In this example, the user is required to pay the fee 40 minutes before the start of the movie, but in real life, the user can also use the mobile phone to settle the bill.

What this app imagine is that a movie can be released in multiple Cinemas at the same time, and a movie theater plays different movies at different times.

I didn't think too much about error handling here, because this is not the focus of this chapter. You can add it on your own.

For simplicity, I used Access 97 as a database. Of course, the real system will not use it. Other databases, such as SQL Server, do not need to change much code.

  Database charts 

  Database charts

The. Movie and theater tables are obviously needed. The show table is used to track the number of available vacancies available for sale.

How to debug this program

To access this WAP service, you need a WAP simulator. This program is mainly debugged on Nokia toolkit 1.2. For details, refer to the previous chapter.

  Select movie 

Select a movie from the List table:

Here is the code:

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

Response. contenttype = \ "text/vnd. WAP. WML \"

The first thing is to declare WML. How does the simulator declare XML not in the correct place? It will not accept WML. Although Nokia 7110 can ignore this, it cannot ensure that other mobile phones can do the same, so you have to do this. You also need to set the MIME type.

<? 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 flickering screen to display a new format of wbmp for an image. This event is determined by the timer attribute. Here we set the time to 5 seconds. After the ontimer event is triggered, we will take you to another card. (wmbp's Photoshop plug-in can be downloaded for free from the Internet ).

<Card id = \ "Splash \" ontimer = \ "# card1 \" Title = \ "Welcome to \"> <timer value = \ "50 \"/>

<P align = \ "center \">

<Br/>

</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 while not rsmovies. EOF

Response. write (\ "<option value = '\" & rsmovies (\ "movie_id \") & \ "'> \" & rsmovies (\ "title \") & \ "</option> \" & vbcrlf)

Rsmovies. movenext

Loop %>

</SELECT>

This part 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 brand new server and it looks different. This also makes me think that the Web programming ASP on WML-based commercial sites is better than Java Servlet.

The following is a reference clip:
<Small> <anchor Title = \ "next! \ "> Next

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

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

</Go>

</Anchor>

</Small>

</P>

You can also use the DO and anchor functions to submit a form. Here, I use a simple embedded link, because it makes the user feel intuitive and friendly. Postfields is similar to Den den in HTML, but WML variables do not need to be transmitted in Javascript as in HTML. They can be directly written in WML. This is explained in the previous section. the transfer method here is get, the POST method is also supported in the WAP specification, and the simulator can also identify it, but unfortunately, in Nokia 7110, this post is not supported, so you have no choice.

 

Select cinema and release time

This part of the Code allows users to choose when to watch movies. All the records are determined based on the movies selected on the previous page. Select the cinema and the release time here.

The following is a reference clip:
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 have carefully studied this code, you will want to use the session to save the movie information, and it is easier to query it on this page. Unfortunately, session is supported by cookies. Although it is also supported in the WAP specification, It is not supported in Nokia 7110, this means that the session cannot be used in the WAP service.

The following are some interesting things:

The following is a reference clip:
<Select name = 'show'>
<%
Do while not rsshows. EOF
Response. write (\ "<option value = '\" & rsshows (\ "show_id \") & \ "'> \" & left (rsshows (\ "Name \"), cutter) & \ "(\" & rsshows (\ "time \") & \ ") \" & \ "</option> \" & vbcrlf)
Rsshows. movenext
Loop %>
</SELECT>

If you are confused about the cutter variable, there are some things that make you laugh and cry.

The following is a reference clip:
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 a good reason to do this. The Nokia toolit 1.2 simulator prefers to cut off my options to only a few characters, and we want to display the movie name and release time, therefore, we have to reduce the characters of the movie name. This problem does not occur in real mobile phones, so we must first determine the device type.

Once I Have A Chance (I am poor and have no money, this is just a distant dream .......) test my code on Nokia 7110 and we immediately feel that we have a larger screen than we think. In fact, some cinema names are odd, and these long names occupy a large screen space. We do not need to waste these display spaces and try to simplify these names.

The next step is to let the user select the expected number of votes. This part of code is similar to other parts. I will query the same data from the database, because the session cannot be used in the real WAP mobile phone, so I have to confirm some content to see if there are seats for sale.

The following is a reference clip:
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> \ "& vbcrlf)
I = I + 1
Loop %>
</SELECT>

  Number of stored tickets

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

The following is a reference clip:
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.exe cute (sqlquery)
Maxbookid = rsbooking (\ "bookingnumber \") + 1
Sqlinsert = \ "insert into booking (show_id, booked_seats )\"&_
\ "Values ('\" & show_id & \ "', '\" & tickets &\"')\"
Conn. Execute (sqlinsert) %>
You have booked <% = tickets %> ticket (s) for <% = movie_title %> <br/>
The show will take place at <% = theater_name %> (<% = time %>)
<Br/>
Your reference number is <% = maxbookid %>

Shown below:

Figure 4: complete the transaction.

The transaction has been completed, and the cinema can receive money at the door of the cinema.

  Conclusion

WAP has just taken its first step, but it is one of the most revolutionary IT developments in recent years. In this article, I will introduce how to use ASP to write WAP applications and give you some warnings. I hope it will be useful for your future development. Multimedia technology cannot be used too much for WAP, but its mobility is important and provides a lot of business opportunities for sellers.

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.