JAVA Web Interface Development Brief

Source: Internet
Author: User

Catalogue

1. JAVA WEB Interface Development Brief

1.1. Basic Understanding

1.2. providing interfaces

1.3. Calling Interfaces

1.JAVA WEB Interface Development brief 1.1.Basic Understanding

when we want to visit the interface of other websites, but do not want to login verification and other operations, then we can choose to use the interface provided by the platform to call to get the information we need. For example, a site a has an interface path: http://192.168.10.119:8080/xmq/webservice/menu/search?ak=APP00013&token= Yq6zaljwyma1x83r0hshvhq45da%3d

when we need to call this interface, we must satisfy the ak parameter and the token parameter. At this point, we need to splice such a URL, and then invoke the platform-provided jar package or other tools to get the information.

1.2.provide interface

ensure that the site A provided invocation interface can be used, where the interface is developed, you need to define some rules, such as the specific return data definition, status code definition, etc., so that the call is clearer. The specific development should be decided according to the actual situation.

1.3.Calling Interface

Such interfaces may be used for these jar packages, such as:

Of course, there are related jar packages such as JSON , which need to determine which specific jar packages are needed based on the site being called .

commonly used classes such as HttpClient,httpget,httppost,httpdelete and so on.

Simple Call HttpGet:

1 protected HttpClient C; 2 3 New httpget (URL; 4 5 HttpResponse response = C.execute (get);

Simple Call HttpPost:

1 New httppost (URL); 2 3 New Stringentity (JSON, Contenttype.create ("Text/plain", "UTF-8")); 4 5 post.setentity (entity); 6 7 response = C.execute (POST);

Simple Call Httpdelete:

1 New httpdelete (URL); 2 3 HttpResponse response = c.execute (delete);

  

we can deal with response , for example:

1 //200 for Success status code2 3 if(Response.getstatusline (). Getstatuscode () = = 200){4 5String ResponseText =NULL;6 7     Try {8 9ResponseText = entityutils.tostring (Response.getentity (), "UTF-8");Ten  One}Catch(ParseException e) { A  -       e.getmessage (); -  the}Catch(IOException e) { -  - e.getmessage (); -  +     } -  +     //return Data processing ResponseText A  at    //typically JSON data format, which is processed according to actual requirements -  -}Else{ -  -     //exception Information Response.getstatusline (). Getstatuscode (); -  in}

JAVA Web Interface Development Brief

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.