jsonobject

servlet中的doGet()与doPost()以及service()的用法

柔情痞子 提交于 2019-12-06 12:49:20
doget和dopost的区别 get和post是http协议的两种方法,另外还有head, delete等 1.这两种方法有本质的区别,get只有一个流,参数附加在url后,大小个数有严格限制且只能是字符串。post的参数是通过另外的流传递的,不通过url,所以可以很大,也可以传递二进制数据,如文件的上传。 2.doGet在地址栏中显示请求的内容,doPost隐藏. 其时说来很简单,在servlet中doPost方法里还是调用了doGet方法,所以在创建servlet时可以不要doPost方法,但在做大型项目涉及密码的传送时doPost方法会更安全些,通常情况下二者没什么区别。 在servlet开发中,以doGet()和doPost()分别处理get和post方法。 首先判断请求时是get还是post,如果是get就调用doGet(), 如果是post就调用doPost()。都会执行这个方法。 1.doGet GET 调用用于获取服务器信息,并将其做为响应返回给客户端。当经由Web浏览器或通过HTML、JSP直接访问Servlet的URL时,一般用GET调用。 GET调用在URL里显示正传送给SERVLET的数据,这在系统的安全方面可能带来一些问题,比如用户登录,表单里的用户名和密码需要发送到服务器端, 若使用Get调用,就会在浏览器的URL中显示用户名和密码。 例:

发送短信验证码的JAVA代码

旧时模样 提交于 2019-12-06 12:18:49
package com.moretickets.platform; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import sun.rmi.runtime.Log; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SendSMSCode { private int countSeconds = 60;//倒计时秒数 private EditText mobile_login, yanzhengma; private Button getyanzhengma1, login_btn; private Context mContext; private String usersuccess; private Handler mCountHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (countSeconds > 0) { --countSeconds; getyanzhengma1.setText

Create json Object by java from data of mysql

本秂侑毒 提交于 2019-12-06 09:12:20
问题 After getting data from mysql, I need to export data as JSON,like the format as follows: {"Thong tin":[{"Ngay":"2013-06-18","Tinh":"An Giang"},{"Ngay":"2013-06-17","Tinh":"Bình Dương"},{"Ngay":"2013-06-16","Tinh":"Bạc Liêu"}]} But what i get , it's like {"Thong tin":[{"Ngay":"2013-06-16","Tinh":"Bạc Liêu"},{"Ngay":"2013-06-16","Tinh":"Bạc Liêu"},{"Ngay":"2013-06-16","Tinh":"Bạc Liêu"}]} Can you help me fix this error? My code: acc = new access(); rs2 = acc.query("select province_Name, date

gzip压缩

China☆狼群 提交于 2019-12-06 08:13:35
public class GzipDemo{ public static void main(String[] args) throws IOException { JSONObject request = new JSONObject(); String originStr = JSON.toJSONString(request); byte[] dess = compressToByte(originStr); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(dess); byteArrayEntity.setContentEncoding("gzip"); byteArrayEntity.setContentType("application/json"); HttpUriRequest gzip = RequestBuilder.post("url") .setEntity(byteArrayEntity) .setHeader("xxx-content","gzip") .build(); JSONObject post = LocalHttpClient.executeJsonResult(gzip); System.out.println(JSON.toJSONString(post)); } public

springboot项目实用代码整理

扶醉桌前 提交于 2019-12-06 06:25:35
// 判断JSONOBJECT是否为空 CommonUtils.checkJSONObjectIsEmpty(storeInfo) // 判断字符串是否为空," "也为空 StringUtils.isBlank(areaId) // List<Object>转换成JSONArray CommonUtils.listJSObjectCovertJr() // 字符串是否非空 " "算空 StringUtils.isNotBlank(supNo) // 获取字符串,把null自动转换为空字符串 CommonUtils.getString() // 把整形转换为字符串型 String.valueOf(mocType) // 字符串型转换为JSONObject如果字符串异常,会抛异常返回一个空的JSONObject CommonUtils.getJSONObject(dataStr) // 判断所给的字符串是否只包含数字,空字符串也会返回false StringUtils.isNumeric(orderNo) // 判断字符串orderDate 是否符合日期格式 ValidateUtil.checkDate(orderDate, "YYYY-MM-dd") // 判断字符串subType是否是一个整数 ValidateUtil.checkIsInteger(subType) 来源:

java原生get和post请求(基于java 1.8)

余生颓废 提交于 2019-12-06 05:49:55
package com.moucong;import com.alibaba.fastjson.JSONObject;import java.io.*;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.text.ParseException;public class get_post { /** * Created by chengxia on 2018/12/4. */ public String doPost(String URL){ OutputStreamWriter out = null; BufferedReader in = null; StringBuilder result = new StringBuilder(); HttpURLConnection conn = null; try{ URL url = new URL(URL); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); //发送POST请求必须设置为true conn.setDoOutput(true); conn

Converting JSONObject to JSONArray

北战南征 提交于 2019-12-06 04:26:48
问题 I'm currently learning some android programming with JAVA. My teacher shared this piece of code which will consume an API, get its JSON file, and convert it to a JSONArray file. Then he will Iterate through that JSONArray and put them into an ArrayList before displaying them onto an activity. The problem is that the API that I'm consuming returns a JSONObject file instead, and I do not know how to properly convert this to JSONArray. import android.util.Log; import org.json.JSONArray; import

JSONObject的详细看法

浪子不回头ぞ 提交于 2019-12-06 03:44:17
先来看下它有哪些常用方法,以及有什么作用: 1.put(String key, Object value)方法,在JSONObject对象中设置键值对在,在进行设值得时候,key是唯一的,如果用相同的key不断设值得时候,保留后面的值。 2.Object get(String key) :根据key值获取JSONObject对象中对应的value值,获取到的值是Object类型,需要手动转化为需要的数据类型 3.int size():获取JSONObject对象中键值对的数量 4.boolean isEmpty():判断该JSONObject对象是否为空 5.containsKey(Object key):判断是否有需要的key值 6.boolean containsValue(Object value):判断是否有需要的value值 7.JSONObject getJSONObject(String key):如果JSONObjct对象中的value是一个JSONObject对象,即根据key获取对应的JSONObject对象; 8.JSONArray getJSONArray(String key) :如果JSONObject对象中的value是一个JSONObject数组,既根据key获取对应的JSONObject数组; 9.Object remove(Object key)

Java JSONObject get children

限于喜欢 提交于 2019-12-06 01:00:48
i want to create gmaps on my website. I found, how to get coordinates. { "results" : [ { // body "formatted_address" : "Puławska, Piaseczno, Polska", "geometry" : { "bounds" : { "northeast" : { "lat" : 52.0979041, "lng" : 21.0293984 }, "southwest" : { "lat" : 52.0749265, "lng" : 21.0145743 } }, "location" : { "lat" : 52.0860667, "lng" : 21.0205308 }, "location_type" : "GEOMETRIC_CENTER", "viewport" : { "northeast" : { "lat" : 52.0979041, "lng" : 21.0293984 }, "southwest" : { "lat" : 52.0749265, "lng" : 21.0145743 } } }, "partial_match" : true, "types" : [ "route" ] } ], "status" : "OK" } I

接口调用post请求参数在body中

走远了吗. 提交于 2019-12-05 21:04:55
package com.ynhrm.common.utils; import com.alibaba.fastjson.JSONObject; import lombok.Data; import org.apache.http.Consts; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import