📄 wap builds java applications.htm
字号:
<TD height=1><IMG height=5 alt=""
src="WAP builds Java applications.files/c.gif"
width=160></TD></TR>
<TR>
<TD><A
href="http://www-106.ibm.com/developerworks/subscription/">dW
Subscription<BR
xmlns:fo="http://www.w3.org/1999/XSL/Format">(CDs and
downloads)</A></TD></TR>
<TR>
<TD height=1><IMG height=5 alt=""
src="WAP builds Java applications.files/c.gif"
width=160></TD></TR>
<TR>
<TD height=1><IMG height=5 alt=""
src="WAP builds Java applications.files/c.gif"
width=160></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=160 border=0>
<TBODY>
<TR>
<TD width=150 bgColor=#000000 colSpan=2 height=2><IMG height=2
alt="" src="WAP builds Java applications.files/c.gif"
width=160></TD></TR>
<TR>
<TD width=150 bgColor=#ffffff colSpan=2 height=2><IMG height=2
alt="" src="WAP builds Java applications.files/c.gif"
width=160></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><SPAN
class=atitle2>Take advantage of your existing EJBs to power a mobile
workforce</SPAN><BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR vAlign=top align=left>
<TD>
<P>Level: Introductory</P></TD></TR></TBODY></TABLE>
<P><A
href="http://www-106.ibm.com/developerworks/java/library/wi-entwap/?open&l=766,t=grj,p=WAPjApps#author1"><NAME>Aashish
Patil</NAME></A> (<A
href="mailto:ash01@vsnl.net?cc=&subject=WAP builds Java applications">mailto:ash01@vsnl.net?cc=&subject=WAP
builds Java applications</A>)<BR>M.S. candidate, Computer Science
department, University of Southern California<BR>01 Jul 2001</P>
<BLOCKQUOTE>If your company already relies on multitiered enterprise
Java applications, then you may be closer to a wireless future than you
think. By outlining a sample application, Aashish Patil shows you how to
connect your existing enterprise Java infrastructure to a wireless
netowrk with minimal investment in equipment and labor. Using existing
EJBs, modified servlets, and new WML and WMLScript pages makes the
process a snap.</BLOCKQUOTE>
<P>The Wireless Application Protocol (WAP) can add value to the existing
Web architecture of an enterprise. If you are already using enterprise
Java applications, you can easily integrate them with WAP services to
bring useful data and functionality to a mobile workforce. In this
article, I will cover the basics of using J2EE with WAP and then build a
sample WAP/enterprise Java application that demonstrates how you can
connect your own EJBs to a wireless network.</P>
<P><A name=N10038><SPAN class=atitle2>Background: J2EE and
WAP</SPAN></A><BR>You should have a basic understanding of the Java 2
Platform, Enterprise Edition (J2EE) architecture before reading this
article. You can find links to more information on J2EE in the <A
href="http://www-106.ibm.com/developerworks/java/library/wi-entwap/?open&l=766,t=grj,p=WAPjApps#resources"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Resources</A>
section below. As a refresher, here's a diagram of a typical J2EE
application designed with a desktop client in mind:</P>
<P><A name=N10048><B>Figure 1. J2EE application structure</B></A><BR><IMG
height=318 alt="J2EE application structure"
src="WAP builds Java applications.files/wapj2ee-fig1.gif" width=556
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></P>
<P>In Figure 1, the layer containing the JavaServer Pages (JSPs) and
servlets is responsible for the generation of dynamic HTML pages. In WAP
applications, this layer would generate dynamic Wireless Markup Language
(WML) pages instead. Thus, in order to alter a standard J2EE app for use
with mobile devices, you will have to write new JSPs and, in some cases,
new servlets. The Enterprise JavaBeans (EJBs) will be left untouched,
since they are not concerned with presentation of data.</P>
<P>
<TABLE cellSpacing=0 cellPadding=5 width="30%" align=right border=1>
<TBODY>
<TR>
<TD background="WAP builds Java applications.files/bg-gold.gif">
<P><A name=N1005A><B>What is WML?</B></A><BR></P>Just as Web
browsers display data encoded in HTML, WAP-enabled devices display
data encoded in Wireless Markup Language (WML); and, just as Web
developers can use JavaScript to embed scripting functionality into
Web pages, device developers can use WMLScript to embed the same
kind of functionality into WML pages. WML is a subset of XML and
will look familiar to anyone versed in HTML or other markup
languages. One unique feature of WML to keep in mind is that of a <I
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">deck</I> of <I
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">cards;</I>
while a single HTML document displays as a single Web document, a
single WML document can contain multiple cards. The WAP device
screen will only display a single card at a time. Some WML and
WMLScript links are available in the <A
href="http://www-106.ibm.com/developerworks/java/library/wi-entwap/?open&l=766,t=grj,p=WAPjApps#resources"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Resources</A>
section below. </TD></TR></TBODY></TABLE></P>
<P>Some would argue that the servlets do not need to be changed, either: a
simple redirection of their output to JSPs generating dynamic WML pages
should be sufficient. However, a servlet cannot differentiate between
requests coming from desktop computers and requests coming from WAP
devices; since WAP applications may not implement all the functionality of
a Web-based architecture, it is important that there be no confusion in
this regard. Hence, developers usually design new servlets for WAP
applications. However, these servlets will, in most cases, be very similar
to servlets that provide similar functionality over a Web-based
architecture. </P>
<P>Another component that does not appear in Figure 1 but is crucial to
WAP applications is a <I xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">WAP gateway.</I>
This component is responsible for conversions from the WAP stack to the
Internet stack and vice versa. </P>
<P>Figure 2 is a revised version of Figure 1, showing the structure for a
J2EE application with a WAP device as a client:</P>
<P><A name=N1007A><B>Figure 2. WAP/J2EE application
structure</B></A><BR><IMG height=176 alt="WAP/J2EE application structure"
src="WAP builds Java applications.files/wapj2ee-fig2.gif" width=489
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></P>
<P>As noted, all requests to the Web server from a WAP client must be
routed through a WAP gateway. Although a WAP gateway can also act as a WAP
server by hosting WML/WMLScript pages, it is more convenient to host these
on the Web server.</P>
<P>There are many deployment scenarios for the WAP gateway. For most WAP
applications, the gateway is either deployed by the ISP or by the company
hosting the application. The latter scenario is the more secure choice, as
we'll see later; however, if users want general-purpose network access on
their WAP devices, an internal WAP gateway can be an inconvenience. Most
non-ISPs would not want their gateways to be used to access sites other
than their own; hence, to visit other sites, users will have to use an
ISP's gateway. But for every gateway used by the WAP client, the user has
to define a different connection, just as one does in Windows 98's Dialup
Networking -- and the number of such connections available on each device
is usually limited. This adds inconvenience for the user and it also
blocks a connection in a WAP device for access to a single site.</P>
<P><A name=N1008D><SPAN class=atitle2>WAP application design
considerations</SPAN></A><BR>A developer used to building J2EE apps for
desktop clients will run into some new challenges when working with WAP.
The following are some questions you might find yourself asking while
building a WAP application.</P>
<P><I xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">How many lines can I
display on a screen?</I> <BR xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Actually, there is
no specific limitation on the number of lines that can be displayed as
long as the maximum deck size limit (which varies from device to device)
is not exceeded. However, in order to avoid too much scrolling, five to
seven lines per screen (i.e., card) is a good limit.</P>
<P><I xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">What security issues
should I consider?</I> <BR xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Some phones do not
support the <CODE>POST</CODE> method of sending form data. Hence, a
username and password must be sent by the <CODE>GET</CODE> method. At the
WAP gateway, if the logging function is activated and if the request is
logged, the administrator will be able to see the username and password.
This would be particularly problematic if the gateway were hosted by an
ISP or other third party.</P>
<P>Even a secure connection does not completely eliminate insecurity. The
data sent to the WAP gateway is encrypted using WTLS (Wireless Transport
Layer Security), which uses the same algorithm as standard TLS. However,
the data sent to the WAP gateway is binary encoded (for WAP), so the
encrypted data must be decrypted and re-encrypted using TLS for the
Internet. For some time, the sensitive data is in clear text on the WAP
gateway. A hacker could perform a memory dump at the right time and then
gain access to this sensitive data.</P>
<P>As noted, one way to get around this problem is to have the WAP gateway
at your own company's end instead of at the ISP's. In that case, a trusted
person could handle the gateway and the logging function could be turned
off.</P>
<P>You could also use a custom encryption algorithm to encrypt the
username and the password at the client end using WMLScript. This is
possible only if you use simple algorithms; WMLScript is not powerful
enough to support algorithms of the DES category. </P>
<P><I xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">How can I maintain a
session?</I> <BR xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">WAP clients do not
support cookies. Thus, in order to maintain information about the client
on the server side as he navigates through the various pages of your site,
a session ID must be passed as a parameter along with every request sent
to the server. The parameter name for this session ID is different for
different servlet engines.</P>
<P>Sometimes, the default session ID length increases the length of each
request considerably. As a result, the client or the WAP gateway may
reject the request as a malformed URL. It is necessary to reduce the
length of the session ID. See the documentation of the servlet engine that
you are using for the parameter name of the session ID. If you are
experiencing malformed URL errors, this documentation should also offer
guidance on reducing the length of the session ID value.</P>
<P><A name=N100C0><SPAN class=atitle2>Building the sample
application</SPAN></A><BR>XYZ Ltd. manufactures PDAs, wearable computers,
and other pervasive computing devices. The company's sales staff visits
clients to offer live demonstrations of XYZ's products; for some of these
demonstrations, salespeople must travel great distances to reach client
sites. How will they receive client lists and other vital data while on
the road?</P>
<P>Using e-mail for this purpose would require bulky, expensive laptops or
never-ending searches for Internet cafés; using fax machines at client
sites would be even more impractical. Instead, XYZ's sales crew will
receive their data via WAP-enabled devices, such as mobile phones or PDAs.
Using a mobile device, the salesperson can provide immediate feedback to
the company on the status of the client visit. The company could then
arrange immediate delivery of goods to the client and maintain current
sales statistics.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -