javaschmea的简单介绍

博主:adminadmin 2023-01-20 03:45:09 378

本篇文章给大家谈谈javaschmea,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java中用什么方法调用远程url并接收其返回的xml或json

可以直接通过get方式或者post方式工具类来实现:

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.security.KeyStore;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.apache.commons.httpclient.methods.PostMethod;

import org.apache.commons.httpclient.methods.RequestEntity;

import org.apache.commons.httpclient.methods.StringRequestEntity;

import org.apache.http.HttpResponse;

import org.apache.http.NameValuePair;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.HttpClient;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.conn.scheme.Scheme;

import org.apache.http.conn.ssl.SSLSocketFactory;

import org.apache.http.entity.ByteArrayEntity;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.util.EntityUtils;

/**

* Http 工具类 ,依赖org.apache.http.* 和 org.apache.commons.httpclient.*

*

*

* @date 2015 -09-14 上午9:56:10

*

* @author gaodebao

*

*/

public class CMBCHttpUtil {

private static final String DEFAULT_ENCODING = "GBK";

/**

* GET方式请求

*

* @param uri

* 服务器的uri要用物理IP或域名,不识别localhost或127.0.0.1形式!

* @return

* @throws IOException

* @throws ClientProtocolException

*/

public static String get(String uri) throws ClientProtocolException,

IOException {

HttpGet httpGet = new HttpGet(uri);

HttpClient httpClient = new DefaultHttpClient();

HttpResponse httpResponse = httpClient.execute(httpGet);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

String result = EntityUtils.toString(httpResponse.getEntity());

return result;

}

throw new IOException("status is " + statusCode);

}

public static String get(String uri, MapString, String paramMap)

throws ClientProtocolException, IOException {

StringBuilder sb = new StringBuilder(uri);

if (paramMap != null) {

boolean isBegin = true;

for (String key : paramMap.keySet()) {

if (isBegin) {

sb.append("?").append(key).append("=")

.append(paramMap.get(key));

isBegin = false;

} else {

sb.append("").append(key).append("=")

.append(paramMap.get(key));

}

}

}

HttpGet httpGet = new HttpGet(sb.toString());

HttpClient httpClient = new DefaultHttpClient();

HttpResponse httpResponse = httpClient.execute(httpGet);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

String result = EntityUtils.toString(httpResponse.getEntity());

return result;

}

throw new IOException("status is " + statusCode);

}

/**

* GET方式请求https

*

* @param uri

* 服务器的uri要用物理IP或域名,不识别localhost或127.0.0.1形式!

* @return

* @throws IOException

* @throws ClientProtocolException

*/

public static String httpsGet(String uri, String keyFile, String keyPwd)

throws Exception {

HttpGet httpGet = new HttpGet(uri);

HttpClient httpClient = newHttpsClient(keyFile, keyPwd);

HttpResponse httpResponse = httpClient.execute(httpGet);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

String result = EntityUtils.toString(httpResponse.getEntity());

return result;

}

throw new IOException("status is " + statusCode);

}

/**

* POST方式请求

*

* @param uri

* 服务器的uri要用物理IP或域名,不识别localhost或127.0.0.1形式!

* @param paramMap

* @return

* @throws IOException

* @throws ClientProtocolException

*/

public static String post(String uri, MapString, String paramMap)

throws ClientProtocolException, IOException {

System.out.print(uri);

HttpPost httpPost = new HttpPost(uri);

ListNameValuePair params = new ArrayListNameValuePair();

if (paramMap != null) {

for (String key : paramMap.keySet()) {

params.add(new BasicNameValuePair(key, paramMap.get(key)));

}

httpPost.setEntity(new UrlEncodedFormEntity(params,

DEFAULT_ENCODING));

}

HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

return EntityUtils.toString(httpResponse.getEntity());

}

throw new IOException("status is " + statusCode);

}

/**

* POST方式请求

*

* @param uri

* 服务器的uri要用物理IP或域名,不识别localhost或127.0.0.1形式!

* @param paramMap

* @param headers

* @return

* @throws ClientProtocolException

* @throws IOException

*/

public static String post(String uri, MapString, String paramMap,

MapString, String headers) throws ClientProtocolException,

IOException {

HttpPost httpPost = new HttpPost(uri);

if (headers != null) {

for (String key : headers.keySet()) {

httpPost.setHeader(key, headers.get(key));

}

}

ListNameValuePair params = new ArrayListNameValuePair();

if (paramMap != null) {

for (String key : paramMap.keySet()) {

params.add(new BasicNameValuePair(key, paramMap.get(key)));

}

httpPost.setEntity(new ByteArrayEntity(paramMap.get("reqData").getBytes("UTF-8")));

// httpPost.setEntity(new UrlEncodedFormEntity(params,

// DEFAULT_ENCODING));

}

HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

return EntityUtils.toString(httpResponse.getEntity());

}

throw new IOException("status is " + statusCode);

}

public static String post(String uri, String contentType, String content)

throws Exception {

org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();

PostMethod post = new PostMethod(uri);

RequestEntity entity = new StringRequestEntity(content, contentType,DEFAULT_ENCODING);

post.setRequestEntity(entity);

int statusCode = client.executeMethod(post);

if (statusCode == 200) {

return post.getResponseBodyAsString();

}

throw new IOException("status is " + statusCode);

}

// public static String post(String uri, String contentType, String content)

// throws Exception {

// org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();

//

// PostMethod post = new PostMethod(uri);

//

// RequestEntity entity = new StringRequestEntity(content, contentType,DEFAULT_ENCODING);

// post.setRequestEntity(entity);

//

// int statusCode = client.executeMethod(post);

// if (statusCode == 200) {

// return post.getResponseBodyAsString();

// }

// throw new IOException("status is " + statusCode);

// }

/**

* POST方式请求https

*

* @param uri

* 服务器的uri要用物理IP或域名,不识别localhost或127.0.0.1形式!

* @param paramMap

* @return

* @throws IOException

* @throws ClientProtocolException

*/

public static String httpsPost(String uri, MapString, String paramMap,

String keyFile, String keyPwd) throws ClientProtocolException,

IOException, Exception {

HttpPost httpPost = new HttpPost(uri);

ListNameValuePair params = new ArrayListNameValuePair();

if (paramMap != null) {

for (String key : paramMap.keySet()) {

params.add(new BasicNameValuePair(key, paramMap.get(key)));

}

httpPost.setEntity(new UrlEncodedFormEntity(params,

DEFAULT_ENCODING));

}

HttpResponse httpResponse = newHttpsClient(keyFile, keyPwd).execute(

httpPost);

int statusCode;

if ((statusCode = httpResponse.getStatusLine().getStatusCode()) == 200) {

return EntityUtils.toString(httpResponse.getEntity());

}

throw new IOException("status is " + statusCode);

}

/*

* 新建httpsClient

*/

private static HttpClient newHttpsClient(String keyFile, String keyPwd)

throws Exception {

KeyStore trustStore = KeyStore.getInstance("BKS");

trustStore.load(new FileInputStream(new File(keyFile)),

keyPwd.toCharArray());

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);

Scheme sch = new Scheme("https", socketFactory, 8443);

HttpClient client = new DefaultHttpClient();

client.getConnectionManager().getSchemeRegistry().register(sch);

return client;

}

}

java开发,json是干什么的

json其实就是封装了一种数据格式,它使用了自己定义的标准。主要用来在服务器和客户端的浏览器进行数据交换。因为我们常用的表单形式提交数据,有诸多的不便,json解决了一些问题。学习Java开发推荐千锋教育,千锋教育利用技术优势精心打造了AI教辅系统,依托技术领域热门的人工智能技术,科技辅学,有力护航学员成长。

java开发前景好,很多软件的开发都离不开Java,因此其程序员的数量最多。据官方数据统计,在全球编程语言工程师的数量上,Java语言以900万的程序员数量位居首位。Java在我们的生活中无处不在。只要我们能接触到互联网,我们就不能没有Java。目前,世界上有数十亿设备正在运行Java。从互联网电子商务到金融行业的服务器应用,从APP到企事业单位的OA系统,从大数据到桌面应用等,Java广泛应用于各个领域。

想要了解更多关于java开发的相关信息,推荐咨询千锋教育。千锋企合作部整合大量企业客户资源,紧抓当下企业需求,将技术和项目完美结合千锋课程体系,力求培养更多优质人才服务企业,不断提升学员竞争力,链接企业用人标准的培训课程及实战项目,让企业招聘用人的技术要求与千锋学员的技术充分对接。近年来不断引进阿里钉钉小程序技术、红帽认证、腾讯云、亚马逊等,通过与企业的深度融合实现千锋教研和就业服务的迭代升级,专业性值得信赖。

Java 静态内部类作用?

1、变值权限修饰作用,在定义内部类的时候,可以在其前面加上一个权限修饰符static。此时这个内部类就变为了静态内部类。

2、在某些特殊的情况下,少了这个静态内部类还真是不行。如在进行代码程序测试的时候,如果在每一个Java源文件中都设置一个主方法(主方法是某个应用程序的入口,必须具有),那么会出现很多额外的代码。

3、最主要的时这段主程序的代码对于Java文件来说,只是一个形式,其本身并不需要这种主方法。但是少了这个主方法又是万万不行的。在这种情况下,就可以将主方法写入到静态内部类中,从而不用为每个Java源文件都设置一个类似的主方法。

这对于代码测试是非常有用的。在一些中大型的应用程序开发中,则是一个常用的技术手段。

扩展资料

例如:

对于两个类,拥有相同的方法:

class People{

run();

}

interface Machine{

run();

}

此时有一个robot类:

class Robot extends People implement Machine.

此时run()不可直接实现。

interface Machine{

void run();

}

class Person{

void run(){

System.out.println("run");

}

}

class Robot extends Person{

private class MachineHeart implements Machine{

public void run(){

System.out.println("heart run");

}

}

public void run(){

System.out.println("Robot run");

}

Machine.getMachine(){returnnew MachineHeart();

}

class Test{

publicstaticvoid main(String[] args){

Robot robot=new Robot();

Machine m=robot.getMachine();

m.run();

robot.run();

}

}

参考资料来源:百度百科-静态内部类

Java的内部类有什么特点 作用和注意

需要了解2个概念:内部类和静态修饰符static

1)首先,用内部类是因为内部类与所在外部类有一定的关系,往往只有该外部类调用此内部类。所以没有必要专门用一个java文件存放这个类。

2)静态都是用来修饰类的内部成员的。比如静态方法,静态成员变量,静态常量。它唯一的作用就是随着类的加载(而不是随着对象的产生)而产生,以致可以用类名+静态成员名直接获得。

这样静态内部类就可以理解了,因为这个类没有必要单独存放一个文件,它一般来说只被所在外部类使用。并且它可以直接被用

外部类名+内部类名

获得。

以下举例说明怎么使用:

student类有个叫school的内部类(非静态)

student

stu

=

new

student();

stu.school

sch

=

new

stu.school();

sch就是school的一个对象。

假如school是内部静态类:

student.school

sch

=

new

student.school();

然而在开发中并没有什么卵用

oracle中schema指的是什么

Schema,即XML Schema,XSD (XML Schema Definition)是W3C于2001年5月发布的推荐标准,指出如何形式描述XML文档的元素。XSD是许多XML Schema 语言中的一支。XSD是首先分离于XML本身的schema语言,故获取W3C的推荐地位。

像所有XML Schema 语言一样,XSD用来描述一组规则──一个XML文件必须遵守这些规则,才能根据该schema‘合法(Valid)’。

扩展资料:

发展历程

在官方文档的参考附录里,XSD标准承认受到[文件类型描述|DTD]]和其他早期XML schema 语言的影响,如DDML、SOX、XML-Data、以及XDR。XSD从中吸收了一些特性,然而也在这些特性中有所折衷。

这些早期schema 语言中的XDR与SOX在XML Schema发布后仍继续使用了一段时间。不少微软的产品支持XDR直到2006年十二月MSXML6.0的发布(MSXML 6.0抛弃了XDR改用XSD)。

Commerce One, Inc支持它自己的SOX schema 语言直到该公司于2004年末破产。2004年十二月,Novell, Inc.购买了该公司,包括那些与SOX相关的专利,据报导是尽力防止被某些不相关的、以打专利相关官司为生的公司剥削图利。

参考资料来源:百度百科-Schema

关于javaschmea和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。