Test the "Web application javame client" in netbeans6.5"

Source: Internet
Author: User
Tags netbeans

I haven't written a blog for a long time. I have been in a bad mood for the past few days and have no intention of doing things. I just need to code it.

Switching from eclipse to netbeans involves several times, and it is always between them. Let's talk about the "Java me client for Web Applications" in netbeans ". (Sorry, I am using the netbeans6.5 Chinese version. The bug M1 has too many bugs and has been removed ).

This function can basically replace WebService. After all, many terminals still do not support JSR 172.
In fact, it is also a code template that implements remote method calling Based on the HTTP protocol. You can implement it by yourself, but netbeans gives you great convenience.

Let's talk about how to use it.
It is generally recommended that you first create a web application and configure its datasource and other resources.

Create a class for it. If the class name is left blank, I will get it from the original WebService class, called newsservice.
It encapsulates the required business logic and exposes methods for remote calls.

There is nothing special about it. You can do it as you want.

Create your client project, a Java me project, and then right-click it in the project window and choose "New-web application's Java me client ", following the wizard, it is basically OK.

The first step is to configure the interface servlet to implement communication between the client and the server. That is to say, it is responsible for receiving client requests and calling the newsservice class above to complete relevant operations, and then replying to the client.

The second step is to select the class that truly completes the business logic, that is, the previous newsservice, and select which methods it contains to be provided to the remote Java me client for calling.

Step 3 is to configure a client code and a client class, which encapsulates remote methods and converts local method calls to HTTP requests, and convert the server response to the return value of the method.

Netbeans will automatically generate a bunch of code and it will be OK.

Let's take a look at the generated code first at the server side:

Besides the interface servlet, there are two auxiliary classes utility. Java javongateway. Java and one interface invocation=action. java.
Starting from the servlet, its dopost is read in byte stream from the request and the method corresponding to invokemethod.

The Utility Class reads and writes parameters and results. Javongateway is the proxy encapsulation of various remote methods.

Look at the client code, a webtomobileclient. Java and a description file of webtomobileclient. wsclient.

In addition to several methods with the same name as the remote method, webtomobileclient implements the invokeserver, which is responsible for converting local calls into byte streams and sending post requests to the webtomobileservlet on the server.

The only thing you need to note when using this web application client function is that the returned value should not use custom classes as much as possible. I tried and found that if the returned value is a custom type, you also need to modify the utility code for this class, otherwise it will not automatically serialize your custom class, but the Code clearly says, this file is generated. please do not change, conflict!

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.