WAP builds Java applications - turn

xiaoxiao2021-03-06  155

Original source: http://www-900.ibm.com/developerWorks/cn/java/wi-entwap/index.shtml

Make full use of existing EJBs to make the moving population powerful

Aashish Patil (Ash01@vsnl.net) Science Master, Computer Science, Southern California University July 2001

If your company has rely on using multiple layers of business Java applications, then you may be more close to wireless technology than imagination. By describing a sample application, AASHISH PATIL shows you how to connect your existing enterprise Java infrastructure to Wi-Fi in the wireless network. Use existing EJBs, modified servlets, and new WML and WMLScript pages that make this process makes a leap.

WiReless Application Protocol, WAP can improve the amount of gold existing Web architecture. If you have already used the company Java app, you can easily integrate them with WAP services, which can bring useful data and features to mobile groups. In this article, I will involve using the basic elements of J2EE-related J2EE, then create a WAP / Enterprise Java sample application to show you how to connect your EJB to the wireless network.

Background: J2EE and WAP are reading before reading this article, you should have a basic understanding of the Java 2 platform, Enterprise Edition (J2EE) architecture. You can find more information about J2EE through the following reference sections. As a review, the following is a schematic diagram of a typical J2EE application designed for desktop clients.

Figure 1 - J2EE application structure

In Figure 1, the layer containing JavaServer Page (JSP) and servlet is responsible for generating a dynamic HTML page. In WAP applications, this layer will generate a dynamic wireless tag language (WML) page. Therefore, in order to convert a standard J2EE application, you will have to write new JSPs for mobile devices, and in some cases, you have to write new servlets. Enterprise JavaBean (EJB) remains unchanged, because they have nothing to do with data performance.

What is WML? As the web browser displays the data of HTML encoded, the device supports the wireless tag language (WAP) displays the WML encoded data; The function is embedded in the WML page. WML is a subset of XML, and people who are proficient in HTML or other markers seem to be familiar. WML has a unique feature need to be kept in mind: it is like a box of cards; a single HTML document displays a single web document, and a single WML document can contain a lot of cards. A card can only be displayed at a time of the WAP device. For some links to WML and WMLScript, please refer to the reference sections below.

Some people think that servlet does not need to be changed, or saying that as long as the Servlet's output is simply redirected to the JSP that generated a dynamic WML page is already enough. However, servlet cannot distinguish from desktop and requests from the WAP device; since the WAP application may not be able to implement all the features of the web-based architecture, this is not confused in this area, this is important. Because of this, developers are usually designed for WAP applications to design new servlets. However, in most cases, these servlets are very similar to servlets that provide similar functions based on the web-based architecture. Another component that does not appear in Figure 1 but a WAP application is a WAP gateway. This component is responsible for the mutual conversion between the WAP stack and the Internet.

Figure 2 is a modified version of Figure 1 showing the structure of the J2EE application using the WAP device as the client:

Figure 2 - Structure of WAP / J2EE application

According to illustrated, all requests from the WAP client to the web server must be sent via the WAP gateway. Although the WAP gateway can also be placed as a WAP server on the WML / WMLScript page, it is more convenient to place these pages using the web server.

There are many deployment methods for WAP gateways. For most WAP applications, the gateway is deployed by an ISP, or a company that provides this app to deploy. The latter is safer, we will explain later; however, if the user requires multi-purpose network access on their WAP devices, an internal WAP gateway will be very inconvenient. Most non-ISPs don't want their gateways to be used to access other sites other than their own sites; therefore, in order to access other sites, users will have to use ISP gateways. However, for each gateway used by the WAP client, the user must define a different connection, just like the Dialing network of Windows 98 - and on each device, the number of thus connections is usually limited. This increases the user's inconvenience and causes connection blocking in the WAP device when accessing a site.

Consideration of WAP Application Design When using WAP, a habit developers who have written J2EE applications for desktop clients will encounter some new challenges. The following is some of the issues you may encounter when you build a WAP application.

Can I display a few lines of information on the screen? In fact, there is no particular limitation on how many lines showing, as long as it does not exceed the maximum size of the panel (depending on the device). However, in order to avoid too many scrolling, each screen (ie card) is 5 to 7 lines.

What security issues should I consider? Some phones do not support sending form data using the POST method. Therefore, the username and password must be sent via the GET method. On the WAP gateway, if the log function is activated and the request has been recorded, the administrator can see the username and password. If the gateway is provided by ISP or other third parties, this problem will be particularly prominent.

Even if a secure connection does not completely eliminate security hazards. Those data sent to the WAP gateway uses WTLS (Wireless Transport Layer Security) encryption, which uses the same algorithm as standard TLS. However, data sent to the WAP gateway is binary encoding format (for WAP), so these encrypted data must be decrypted and encrypted with TLS to apply to the Internet. After a period of time, sensitive data appears in a plain text in the WAP gateway. The hacker will transfer the information in the memory in the appropriate moment, which will successfully access these sensitive data.

According to the comment, a way to solve this problem is to set a WAP gateway in your own company (not in ISP). In this case, a trusted person can operate the gateway and will turn off the log function. You can also use WMLScript to write a custom encryption algorithm to encrypt the client's username and password. This is only possible when using a simple algorithm; on the algorithm that supports the DES class, WMLScript is not strong enough.

How do I keep session? The WAP client does not support cookies. Thus, when the user shuts down between the different pages of your site, in order to keep the server on the server side, a session ID must be transmitted as a parameter while sending each request to the server. The parameter name of the Session ID is different depending on the Servlet engine.

Sometimes, the default session ID length increases the length of each request. As a result, the client or WAP gateway may see this request as an invalid URL rejection. This is necessary to shorten the length of the session ID. Check out the section of the session ID parameter name for the description documentation of the Servlet Engine you are using. If you encounter an error of an invalid URL, this document should also provide a guide to shorten the length of the Session ID.

Construct Sample Application XYZ Ltd. is a company that produces PDA, wearable computers, and other popular computing equipment. The company's sales staff visited customers, providing a live demonstration of XYZ products; some demosted that sales staff must run a long way to go to customers. So on the road, how do they receive a list of customers and other important data?

To this end, email requires a larger and expensive portable computer or an endless Internet CAF 閟; the client is more unrealistic. Instead, the salesperson of XYZ will receive data, such as mobile phones or PDAs by supporting WAP functions. With mobile devices, salesperson provide timely feedback to the company when visiting customers. The company will immediately arrange the customer to deliver and maintain the current sales statistics.

Our application has two main goals. First, our mobile salesperson should be able to use it on WAP devices to view the customer list. Second, if a customer wants to buy goods, the salesperson should be able to use the device to order. In addition, an important target of any WAP application should be to reduce the number of keys necessary for users. Due to user interface restrictions on hand-held devices, the amount of data that users need to enter should be controlled at least.

This is a flow chart showing the architecture of our system.

Figure 3 - Schematic diagram of application flow

Users must first be logged in to access the system; then they can browse the client list and the details of each customer. If they want to order for a particular customer, the system will provide a list of products that can choose a specific product from it.

In most of the contents of this effort, we will discuss the servlet and JSP code that implements the application and will examine the way JSP and Servlet work together. About each JavaServer Page is also equipped with a graphical, showing the output of JSP on the device screen.

Listing 1, login.jsp accept username and password, and call them as a parameter to call the loginservlet. For this and all other JSPs, the MIME type should be set to the TEXT / VND.WAP.WML type. While passing the request, the above login.jsp also passed a parameter called sessionID. It must be passed along with each request to the server. The parameter name SessionID is a placeholder; please refer to the application server's instruction documentation to find the correct parameter name for your specific application server. Java method httpservletResponse.EncodeURL (String URL) Auto adds the session ID; in our application, this has been widely used in the server. There is a problem when verifying a blank input domain. There is an attribute in the Input tag that lets you make the input domain:

A mobile phone user must access the individual dialog screens to enter data. The problem has appeared because users prefer to choose directly to access the next box or the next card and do not want to enter data by dialog screen. One user may miss the password and lower next when the screen is shown in FIG.

A developer can avoid the occurrence of this problem by using WMLScript verification (by using the onclick event). However, until it enters a value to the input box, the variable you pass to the WMLScript function represents the variable of the input domain value began to be initialized. Therefore, if there is no password to type, it is passed to the function that is not initialized and the script error result. The solution to this problem is to verify all input domains on the server side.

Listing 2, loginservlet is our problem solution: it can authenticate sales staff and record him in the system. It can also create a session to the sales staff on the server side. Note on the code block indicates where these operations will be executed. Once successfully logged in, the device displays the main menu (mainmenu.jsp) shown in Listing 3.

As shown in Figure 5, the file is displayed on the device screen. The second of the second ended the current session; the first point to the current customer list. In the current version of the program process, the salesperson must select a customer from the list before starting any sales transactions; the list of sales products can only be displayed on the subsequent screen (later discussion). There are also other possible procedures: For example, the link used to send users to the product list can be added to the main menu. However, you should not provide too much link in either menu, otherwise the small screen of the device that supports WAP will become unrest.

In the main menu of Figure 5, the View Clients will call the clientViewServlet in Listing 4, which draws the salesperson's list of customers to visit. Note on the code describes how the servlet finds this information from the client. The servlet will then place the list in the Session object and call ClientList.jsp. (The session object mentioned herein is from the httpsession class from the Java Servlet package.)

Listing 5, ClientList.jsp extracts a list of clients placed in the session by ClientViewServlet; it shows the customer's name, but not a complete detailed information (see Figure 6). When a user is selected, the sales person is directed to clientDetails.jsp.

Note: The task that displays the client list is done by three separate parts - ClientViewServlet, ClientList.jsp, and ClientDetails.jsp. What is the reason why this is designed? Most J2EE architectures suggest that JSP should not directly access EJB; and the intermediates such as servlet should be used to interact with EJBs. ClientViewServlet Accesses EJB and gets a list of customers. This application can be designed so that all user information will be included in a single WML document. In this architecture, the client list is included on a card in the WML box, while the detailed information of a single customer will be included on different cards in the same box. However, the single document may contain too many data so that you can't download a low-bandwidth WAP device. If the number of customers is too large, the total amount of data generated is easy to exceed the maximum capacity allowed by the WML card box. (The maximum capacity is different from the device; if the maximum compilation card case capacity of NOKIA 7110 is 1.3 KB). So we use two JSP: ClientList.jsp - Display the list of customers, and ClientDetails.jsp - Display the details of a single customer.

Listing 6, ClientDetails.jsp Accepts the index number of the customer array as a parameter, where the index number appears in the session. Next it extracts the details of the selected customer and display it. If the sales staff wants to order under the customer, he just wants to drop the Items button. This will call the list 7, itemListServlet, and display the optional product of the order.

Listing 7, ItemListServlet draws a list of products that can be sold and place the list in Session. Then it calls a list 8, itemlist.jsp.

Listing 8, itemlist.jsp extracts a list of products from the session and displays the product name. Salesperson can choose a product to order and pull the Order button to call PlaceOrder.jsp. The index of the selected product selected in the array is sent to the list 9, PlaceOrder.jsp.

PlaceOrDervlet obtains the ID of the salesperson, customer and product from the session. A new order can then be generated by creating a new Order Entity EJB. The order of success is displayed and the order of the order of the order is displayed.

In this version of the app, the salesperson is the only choice after the transaction is to return to the main menu (see Figure 9). You can also modify the code to return the user to the customer or product list.

If you pay attention to observation, you will find that the salesperson only enters two data: when logging in, and when you enter the number of purchases for your customers.

About the code with all the JSP and Servlet code all of this article, also contains the necessary EJB code. The EJB's JAR file and deployment descriptor are also included. All screenshots are from the Nokia WAP Simulator 2.0.

Conclusion As mentioned earlier, WAP applications provide very good value-added services. An isolated WAP application is not available. However, such an application can easily integrate into an existing web application architecture without spending a lot of financial manpower. The only new hardware you need is a machine, as well as software for WAP gateways; if you use your ISP gateway, then this overhead can also be saved.

The existing HTML page needs to be converted to WML. However, WML is not as complex as HTML because it does not support many features of HTML. Therefore, this is not a fee.

WAP also supports pictures in Wireless Bitmap (WBMP) format. However, users who use WAP devices spend a lot of money on the connection time, they are more interested in direct effective information rather than luxurious interfaces. Unless the picture itself can transmit information, it will be better than the footprint than the occupation of bandwidth and time. Final note: Although the simulator can provide a good environment for testing WAP applications, only when it works with the deployed WAP gateway, WAP app is calculated as a true meaning. Tested. All dynamically generated pages are compiled on the gateway. Therefore, it is necessary to know which version of WAP is supported by your gateway. If the gateway compiler uses only WML 1.1, the page written in WML 1.2 is useless.

Reference

Get the J2EE's introduction from Sun's Java developers (free registration). The "WAP Site Creation" written by Bilal Siddiqui (DeveloperWorks, May 2001) Very well introduced WML and WMLScript. Get more information about WAP, WML, and WMLScript from the WAP Forum, which is a separate organization that is committed to maintaining WAP standards. IBM's WebSphere Application Server can run this article mentioned in this article. You can download the WAP Gateway Software and WAP Device Simulator from NOKIA. Salmon and IBM bring business Java technology for your wireless network. Returns the Wi-Fi Topic or Java Technology Special Zone of DeveloperWorks for more information on wireless and Java technology.

A bachelor's degree from the computer engineering department of the Thadomal Shahani Engineering Technology of India Mumbai shortly after AashiSh Patil. In Tata Consultancy Services, he completed a project on stock trading that supports WAP as an intern; this article is a direct part of the project. This fall, he will go to the University of Southern California to study a master's degree in computer science. Can contact AASHISH via ASH01@vsnl.net.

转载请注明原文地址:https://www.9cbs.com/read-128079.html

New Post(0)