{"id":15471569,"url":"https://github.com/getactivity/mytomcat","last_synced_at":"2025-04-22T13:15:11.545Z","repository":{"id":108699018,"uuid":"96991600","full_name":"getActivity/MyTomcat","owner":"getActivity","description":null,"archived":false,"fork":false,"pushed_at":"2017-10-07T15:10:49.000Z","size":3384,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T13:14:45.792Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/getActivity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-12T09:46:44.000Z","updated_at":"2023-10-02T02:30:24.000Z","dependencies_parsed_at":"2023-03-12T05:16:39.422Z","dependency_job_id":null,"html_url":"https://github.com/getActivity/MyTomcat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getActivity%2FMyTomcat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getActivity%2FMyTomcat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getActivity%2FMyTomcat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getActivity%2FMyTomcat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getActivity","download_url":"https://codeload.github.com/getActivity/MyTomcat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250246727,"owners_count":21398919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T02:20:40.193Z","updated_at":"2025-04-22T13:15:11.488Z","avatar_url":"https://github.com/getActivity.png","language":"Java","readme":"# 简述\n\n# intro\n\n\u003e[点击下载MyTomcat安装程序](https://raw.githubusercontent.com/getActivity/MyTomcat/master/MyTomcat_3.0.apk)\n\n\u003e[Click on the download MyTomcat installation program](https://raw.githubusercontent.com/getActivity/MyTomcat/master/MyTomcat_3.0.apk)\n\n![](/screenshot/MyTomcat1_zh.png)\n![](/screenshot/MyTomcat2_zh.png)\n![](/screenshot/MyTomcat3_zh.png)\n![](/screenshot/MyTomcat4_zh.png)\n![](/screenshot/MyTomcat5.png)\n\n![](/screenshot/MyTomcat1_en.png)\n![](/screenshot/MyTomcat2_en.png)\n![](/screenshot/MyTomcat3_en.png)\n![](/screenshot/MyTomcat4_en.png)\n\n# 欢迎使用MyTomcat\n\n# Welcome to use MyTomcat\n\n\u003e 本文档不再进行维护，[点击查看最新文档](https://github.com/getActivity/MyTomcat)\n\n\u003e This document is no longer maintained, [click to view the latest document](https://github.com/getActivity/MyTomcat)\n\n\u003e 基于HTTP协议制作的服务器，支持GET和POST请求\n\n\u003e Based on the HTTP protocol server, support the GET and POST requests\n\n\u003e 能跨设备进行访问，支持访问和上传文件，断点续传，操作SQLite数据库\n\n\u003e Can other device access, support access and upload files, breakpoint continuingly, SQLite database operation\n\n\u003e 对带中文URL和中文参数有比较好的支持\n\n\u003e With Chinese URL and Chinese parameters have good support\n\n\u003e 支持被局域网（内网）的设备访问，如需要被广域网（外网）的设备访问，请设置内网映射，并联系你的运营商\n\n\u003e Support is a local area network (Intranet) device access, such as the need to be wan (net) device access, please set up the network mapping, and contact your operator\n\n## 访问服务器\n\n## Access to the server\n\n\u003e 服务器与客户端处于同一个设备上\n\n\u003e The client and server in the same device\n\n\thttp://127.0.0.1: + port\n\thttp://localhost: + port\n\n---\n\n\thttp://127.0.0.1:8888\n\thttp://localhost:8888\n\n\u003e 跨设备访问，在同一局域网环境下，使用当前服务器设备的IP地址，推荐使用静态IP\n\n\u003e Different devices for a visit, In the same LAN environment, using the current IP address of the server device, it is recommended to use a static IP\n\n\thttp:// + host address + \":\" + port\n\n---\n\n\thttp://192.168.1.123：8888\n\n\u003e 请注意：模拟器创建的服务端将无法被其他设备访问\n\n\u003e Please note: simulator to create the server will not be able to make other device access\n\n\u003e 如果你想改变访问的主页，请到设置中进行更改\n\n\u003e If you want to change the home page access, please make changes to the Settings\n\n## 访问服务器上的文件\n\n## To access the file on the server\n\n\u003e 若你设置了以 /mnt/sdcard/（SD卡根目录） 为服务目录\n\n\u003e If you set to /mnt/sdcard/ (SD kagan directory) for the service directory\n\n\u003e 若你想访问服务器上的 /mnt/sdcard/MyTomcat.apk 文件\n\n\u003e If you want to access server /mnt/sdcard/MyTomcat.apk file\n\n\u003e 可以使用以下地址进行访问该资源，访问成功将返回响应码200，若这个文件不存在则返回响应码404\n\n\u003e You can use the following address to access the resources, access successfully returns the response code 200, if the file does not exist, it returns the response code 404\n\n\thttp://127.0.0.1:8888/MyTomcat.apk\n\n\u003e 这种方式比较快捷，但并不推荐此方法，推荐如下两种方式\n\n\u003e This way is quick, but does not recommend this method, recommend the following two ways\n\n## GET请求带参数访问服务器上的文件\n\n## GET request with parameter access the file on the server\n\n\u003e 在参数“path”加上需要访问的文件地址，地址根据你设置的服务器目录而定\n\n\u003e In the parameter \"path\" add need to access the file address, the address according to you to set the server directory\n\n\thttp://127.0.0.1:8888/file?path=\n\n\u003e 若你设置了以 /mnt/sdcard/（SD卡根目录） 为服务目录\n\n\u003e If you set to /mnt/sdcard/ (SD kagan directory) for the service directory\n\n\u003e 若你想访问服务器上的 /mnt/sdcard/MyTomcat.apk 文件\n\n\u003e If you want to access server /mnt/sdcard/MyTomcat.apk file\n\n\u003e 可以使用以下地址进行访问该资源，访问成功将返回响应码200，若这个文件不存在则返回响应码404\n\n\u003e You can use the following address to access the resources, access successfully returns the response code 200, if the file does not exist, it returns the response code 404\n\n\thttp://127.0.0.1:8888/file?path=MyTomcat.apk\n\n\u003e 以你的设置的服务目录为基准，以服务目录中的文件路径作为参数，但不包含服务目录所在路径名称\n\n\u003e Based on your setup service directory, to serve in the directory path to the file as a parameter, but does not include the service directory in the path name\n\n\u003e 若你想访问包含中文路径的文件，可以通过对参数值进行编码 “MyTomcat.apk”，请不要对参数名进行编码 “?path=”\n\n\u003e If you want to access files, including the Chinese path can be based on the parameter value is encoded \"MyTomcat.apk\" , careful not to encode parameter name \"?path =\".\n\n\tURLDecoder.decode(String s, String charsetName);\n\n\u003e s：是需要被编码的字符串\n\n\u003e s: it is need to be encoded string\n\n\u003e charsetName：编码的字符编码，建议使用UTF-8，服务器上设置的字符编码必须和此编码一致，否则会导致乱码\n\n\u003e Is coded character encoding, it is recommended to use utf-8, set the character encoding on the server must be in accordance with this code, otherwise it will lead to the messy code\n\n\t\"http://127.0.0.1:8888/file?path=\" + URLDecoder.decode(\"MyTomcat.apk\", \"UTF-8\");\n\n\u003e GET请求也支持中文，步骤比较繁琐，推荐你使用POST请求进行访问\n\n\u003e GET request also supports Chinese, steps more complicated, it is recommended that you use a POST request for a visit\n\n## POST请求带参数访问服务上的文件\n\n## POST request with parameter access the file on the server\n\n\u003e GET和Post请求的区别在于，GET请求的参数是通过URL传递给服务器的，而POST将参数作为输出流传递到服务器\n\n\u003e The difference between the GET and Post requests, the parameters of the GET request is passed through the URL to the server, and Post transfer parameters as the output stream to the server\n\n\u003e 如果你的URL里面包含中文参数，建议使用此方法，你必须确保该服务器上的字符编码支持中文才不会乱码\n\n\u003e If your URL contains Chinese parameters, it is recommended to use this method, you must make sure that the server will not garbled character encoding support Chinese\n\n\u003e 使用基本与GET无太大差别，若想访问上一个例子（GET请求）上的文件\n\n\u003eUsing basic and GET no much difference, if you want to visit an example of the GET request on file\n\n\thttp://127.0.0.1:8888/file\n\n---\n\n\tpath=MyTomcat.apk\n\n---\n\n\tconn.setDoOutput(true);\n\tOutputStream os = conn.getOutputStream();\n\tos.write(\"path=MyTomcat.apk\".getBytes());\n\n## 文件的断点续传\n\n## Breakpoint continuingly on file\n\n\u003e 这个功能需要通过参数进行告知服务器\n\n\u003e This feature requires via parameters to the server\n\n\u003e 你若想获取文件的部分内容，支持GET和POST，GET请求为例子，可以直接在URL加入参数\n\n\u003e If you want to GET part of the file content, support the GET and POST, GET requests for example, can be directly in the URL parameter\n\n\u003e 访问成功将返回响应码200，若这个文件不存在则返回响应码404\n\n\u003e Access successfully returns the response code 200, if the file does not exist then returns a response code 404\n\n\thttp://127.0.0.1:8888/file?path=MyTomcat/MyTomcat.apk\u0026range=1000\n\n\u003e 注意：“range” 参数是指文件内容的起始位置，用于获取文件从这个位置开始后面的内容\n\n\u003e Note: \"range\" parameter is refers to the starting position of the file content, used to get files from this location at the back of the content\n\n## 使用POST请求上传文件\n\n## Use a POST request to upload files\n\n\u003e 上传文件只能使用POST请求的方式进行，不支持GET请求，不支持断点续传\n\n\u003e Upload files can only use a POST request manner, does not support a GET request, does not support breakpoint continuingly\n\n\u003e 建议你不要上传超过 30MB 的文件，否则你的程序可能会内存溢出，请根据你的设备实际情况为准\n\n\u003e It is recommended that you do not upload more than 30 MB of file, otherwise your application may be out of memory, please according to the actual circumstance of your device\n\n\u003e 上传成功后则返回响应码200，上传失败则返回响应码412\n\n\u003eUploaded successfully after it returns the response code 200, upload fails then returns a response code 412\n\n\u003e 需要严格设置读取时长，否则可能会出现文件已经上传但客户端读取响应码超时导致失败，建议这样设置\n\n\u003e To strictly set the read time, otherwise it may appear file has been uploaded but the client reads the response code overtime result in failure, suggest such Settings\n\n\tconn.setReadTimeout((int) (file.length() / 128 + 2048));\n\n\u003e 读取时长是指客户端等待的最大时长，服务器处理完后会立马响应，具体处理时长和网络环境有关\n\n\u003e Read time refers to the biggest client waiting time, after the server processing immediately response, processing time and the network environment\n\n\u003e 这种算法不一定符合程序的要求，请结合实际的需求\n\n\u003e This algorithm may not accord with the requirement of application, combining with the actual demand, please\n\n\u003e 你需要将文件作为POST请求的输出流传递给服务器，同时需要在请求头指定该文件的信息\n\n\u003eYou need to file as the output of the POST request passed to the server, also need the file specified in the request header information\n\n\t//必须使用此属性请求服务器为此文件在服务器上的路径名称，请使用 URLDecoder.decode 编码后再请求\n\t//Must use the property request to the server for this file on the server path name, please use the URLDecoder. Decode code before you request\n\n\tContent-Disposition\n\n---\n\n\t//服务器返回内容长度，使用断点续传则返回你请求的文件大小减去忽略的字节数\n\t//The server returns the content length, using breakpoint continuingly returns you requested file size minus ignore the number of bytes\n\n\tContent-Length\n\n---\n\n\t//你可以设置此属性让服务比对上传后的文件MD5值，若MD5没有指定，则返回响应码200，若MD5与服务器上的文件不符合，则返回响应码412\n\t//you can set this property to service than after the upload file MD5 value, if the MD5 is not specified, it returns the response code 200, if the MD5 and the file on the server does not conform to, it returns the response code 412\n\n\tContent-MD5\n\n## 服务器返回一些响应头信息\n\n## The server returns some response header information\n\n\u003e 注意：只有在使用带参数的请求访问文件和上传文件才会返回这些响应头信息\n\n\u003e Note: only the using request access to the file with parameters and upload files will return these response headers\n\n---\n\n\t//文件在服务器上的名称，希望你的应用给这个文件命名的名称，一般为请求时的文件名\n\t//The name of the file on the server, in the hope that your application for the file name, the name of the general for the request of the file name\n\t//请使用URLDecoder.decode进行解码再使用\n\t//Please use URLDecoder. Decode decoding to use again\n\n\tContent-Disposition\n\n---\n\n\t//服务器返回内容的类型，若这个文件是HTML、TXT、JSON文件\n\t//The server returns the type of content, If this file is, TXT, HTML JSON file\n\t//服务器返回这个文件的文本编码，方便客户端解析文本文件\n\t//The server returns the file text encoding, convenient for the client to parse text file\n\n\tContent-Type\n\n---\n\n\t//服务器返回内容长度，使用断点续传则返回你请求的文件大小减去忽略的字节数\n\t//The server returns the content length, using breakpoint continuingly returns you requested file size minus ignore the number of bytes\n\n\tContent-Length\n\n---\n\n\t//服务器返回文件MD5值，使用断点续传则不会返回此信息\n\t//MD5 value returned from the server files, using breakpoint continuingly will not return to this information\n\n\tContent-MD5\n\n---\n\n\t//服务器返回文件最后修改时间，返回 long 类型的参数\n\t//The server returns the file was last modified time, return to the parameters type of the long\n\n\tLast-Modified\n\n## 操作服务器上的SQLite数据库\n\n\u003e 仅支持操作SQLite数据库，只能使用POST请求，不支持GET请求\n\n\u003e Only supports SQLite database operation, can only use a POST request, does not support a GET request\n\n\u003e 客户端通过JSON文本来请求操作数据库，需要将JSON文本封装到输出流中，然后传递给服务器\n\n\u003e Client requests through JSON text database operation, need to encapsulate a JSON text into the output stream, and then passed to the server\n\n\u003e 服务器会对JSON进行解析，将结果转换成JSON文本返回客户端\n\n\u003e Server will be to parse JSON, transform the results into a JSON text back to the client\n\n\u003e 注意：如果你请求的JSON数据包含中文，请在服务器设置支持中文的字符编码，否则会乱码\n\n\u003e Note: if you request the JSON data contains Chinese, please in the server Settings to support Chinese character encoding, otherwise you will stil messy code\n\n\u003e 目前服务器仅支持以下几种操作数据库的API\n\n\u003e The server only supports the following operations database API\n\n\tpublic void execSQL(String sql, Object[] bindArgs)\n\n---\n\n\tpublic Cursor rawQuery(String sql, String[] selectionArgs)\n\n---\n\n\tpublic long insert(String table, String nullColumnHack, ContentValues values)\n\n---\n\n\tpublic int delete(String table, String whereClause, String[] whereArgs)\n\n---\n\n\tpublic int update(String table, ContentValues values, String whereClause, String[] whereArgs)\n\n---\n\n\tpublic Cursor query(String table, String[] columns, String selection,\n            \t\t\tString[] selectionArgs, String groupBy, String having,\n            \t\t\tString orderBy, String limit)\n\n\u003e 目前服务器只支持解析以上参数的 SQLite 语句，若返回是Cursor会封装成JSON文本输出到客户端\n\n\u003e The server only supports the above analytical parameters of SQLite statement, if the return is the Cursor will be encapsulated into JSON text output to the client\n\n\u003e 你必须熟悉JSON的生成和解析，才能确保服务器能正确识别你的命令\n\n\u003e You must be familiar with to parse and generate JSON, can ensure that the server can correctly identify your order\n\n\u003e API 中的 String 参数类型以 JSONObject 表示，数组参数类型和 ContentValues 参数类型以JSONArray表示\n\n\u003e In the API string parameters type expressed as a JSONObject, array parameter type and ContentValues parameter expressed as a JSONArray\n\n\u003e 如果你不需要为这个参数类型指定任何的JSONObject，可以直接忽略\n\n\u003e If you do not need to specify any for this parameter type JSONObject, can be ignored directly\n\n---\n\n\u003e 你必须在请求的 JSON 中必须指定以下内容\n\n\u003e You must be in request JSON must specify the following content\n\n* path：键为 JSONObject 类型，值为 String 类型，数据库文件所在路径名称，请填写数据库在服务目录中所在位置，不能进行编码，类型为JSONObject\n\n* path: the key for the JSONObject types, the value of type String, the database file path name, location, please fill out the database in the service directory cannot be encoded, type JSONObject\n\n* type：键为 JSONObject 类型，值为 String 类型，操作类型（execSQL、rawQuery、insert、delete、update、query），类型为JSONObject\n\n* type: Key for JSONObject types, the value of type String, operation type (execSQL, rawQuery, insert, delete, update, query), type JSONObject\n\n* 请求参数名称和对应值，若参数类型为String，键为 JSONObject 类型，否则则为 JSONArray 类型\n\n* The request parameter name and its corresponding value, if the parameters of type String, key for JSONObject type, otherwise it is JSONArray type\n\n---\n\n\t{\n\t\t\"path\": \"visit.db\",\n\t    \"table\": \"visit\",\n\t    \"type\": \"query\",\n\t    \"columns\": [\n\t        \"date\",\n\t        \"localName\"\n\t    ]\n\t}\n\n---\n\n\u003e 服务器一定会返回以下 JSON 内容\n\n\u003e The server will return the following JSON content\n\n* result：键为 JSONObject 类型，值为 long 类型，是数据库操作语句返回值或者Cursor对象的总数\n\n* result: Key for JSONObject types, the value of long type, the return value is the database operation statements or the total number of Cursor object\n\n\u003e 另外查询语句返回了cursor对象，服务器会返回以下这些数据\n\n\u003e Another query returns a cursor object, the server will return the following these data\n\n* columnNames：键为 JSONArray 类型，值为 ArrayList 类型，为服务器查询返回的Cursor中所有字段的名称\n\n* columnNames: Key for JSONArray types, the value of an ArrayList, for the server query returns the names of all fields in the Cursor\n\n* cursor：键为 JSONArray 类型，包含着一个或多个 JSONObject ，每一个 JSONObject 中的键和值对应着每一个 Cusror 键和值\n\n* cursor: Key for JSONArray type, contains one or more JSONObject, each JSONObject corresponds to the key and the value each Cusror keys and values\n\n---\n\n\t{\n\t\t\"result\": 16,\n\t    \"columnNames\": [\n\t        \"date\",\n\t        \"localName\"\n\t    ],\n\t    \"cursor\": [\n\t        {\n\t            \"date\": \"2017-02-20 11:16:25\",\n\t            \"localName\": \"10.0.3.15\"\n\t        },\n\t        {\n\t            \"date\": \"2017-02-20 11:18:51\",\n\t            \"localName\": \"10.0.3.15\"\n\t        },\n\t        {\n\t            \"date\": \"2017-02-20 11:18:53\",\n\t            \"localName\": \"10.0.3.15\"\n\t        }\n\t    ]\n\t}\n\n---\n\n\u003e 使用原生的Android API解析\n\n\u003e Using the native API\n\n\tJSONObject jsonObject = new JSONObject(json);\n\tSystem.out.println(\"Test：\" + jsonObject.getLong(\"result\") + jsonObject.getJSONArray(\"columnNames\") + jsonObject.getJSONArray(\"cursor\"));\n\n\u003e 使用Android第三方框架Gson解析\n\n\u003e Using a third party framework Gson parsing\n\n\tGson gson = new Gson();\n\tSQLiteCursorBean bean = gson.fromJson(json, SQLiteCursorBean.class);\n\n## 操作服务器SQLite数据库给出了工具类\n\n## For operating the server SQLite database tools is presented\n\n\u003e SQLiteCursorBean.java：服务器返回的 JSON 文本，可以使用这个类供第三方框架 Gson 进行解析\n\n\u003e SQLiteCursorBean.java: The server returns JSON text, Can use this class to a third party framework Gson parsing\n\n\tpackage com.hjq.mytomcat.bean;\n\t\n\timport java.util.ArrayList;\n\timport org.json.JSONObject;\n\t/**\n\t * @author HJQ\n\t */\n\tpublic class SQLiteCursorBean {\n\t\n\t\t/**\n\t\t * 数据库操作语句返回值或者Cursor的总数\n\t\t * Database operation statements return values or Cursor count\n\t\t */\n\t\tpublic long result;\n\t\t\n\t\t/**\n\t\t * 返回的cursor列名\n\t\t * return cursor column name\n\t\t */\n\t\tpublic ArrayList\u003cString\u003e columnNames;\n\t\t\n\t\t/**\n\t\t * 返回cursor中的结果，这里可以自定义类改变JSONObject作为泛型\n\t\t * return cursor the results in, Here you can customize class change the JSONObject such as generics\n\t\t */\n\t\tpublic ArrayList\u003cJSONObject\u003e cursor;\n\t}\n\n\u003e RequestSQLiteUtils.java：客户端请求服务器的工具类，可以使用这个类快速生成 JSON 文本\n\n\u003e RequestSQLiteUtils.java: Client requests the server tools, you can use this class quickly generate JSON text\n\n\tpackage com.hjq.mytomcat.bean;\n\t\n\timport org.json.JSONException;\n\timport org.json.JSONObject;\n\timport android.content.ContentValues;\n\t/**\n\t * @author HJQ\n\t */\n\tpublic class RequestSQLiteUtils {\n\t\t\n\t\tprivate final static String TYPE_EXECSQL = \"execSQL\";\n\t\tprivate final static String TYPE_RAWQUERY = \"rawQuery\";\n\t\tprivate final static String TYPE_INSERT = \"insert\";\n\t\tprivate final static String TYPE_DELETE = \"delete\";\n\t\tprivate final static String TYPE_UPDATE = \"update\";\n\t\tprivate final static String TYPE_QUERY = \"query\";\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String execSQL(String path, String sql, Object[] bindArg) throws JSONException{\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_EXECSQL);\n\t\t\tJsonUtils.addJSONObject(json, \"sql\", sql);\n\t\t\tJsonUtils.addJSONArray(json, \"bindArg\", bindArg);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String rawQuery(String path, String sql, String[] selectionArgs) throws JSONException{\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_RAWQUERY);\n\t\t\tJsonUtils.addJSONObject(json, \"sql\", sql);\n\t\t\tJsonUtils.addJSONArray(json, \"selectionArgs\", selectionArgs);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String insert(String path, String table, String nullColumnHack, ContentValues values) throws JSONException{\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_INSERT);\n\t\t\tJsonUtils.addJSONObject(json, \"table\", table);\n\t\t\tJsonUtils.addJSONObject(json, \"nullColumnHack\", nullColumnHack);\n\t\t\tJsonUtils.addContentValues(json, \"values\", values);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String delete(String path, String table, String whereClause, String[] whereArgs) throws JSONException{\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_DELETE);\n\t\t\tJsonUtils.addJSONObject(json, \"table\", table);\n\t\t\tJsonUtils.addJSONObject(json, \"whereClause\", whereClause);\n\t\t\tJsonUtils.addJSONArray(json, \"whereArgs\", whereArgs);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String update(String path, String table, ContentValues values, String whereClause, String[] whereArgs) throws JSONException{\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_UPDATE);\n\t\t\tJsonUtils.addJSONObject(json, \"table\", table);\n\t\t\tJsonUtils.addContentValues(json, \"values\", values);\n\t\t\tJsonUtils.addJSONObject(json, \"whereClause\", whereClause);\n\t\t\tJsonUtils.addJSONArray(json, \"whereArgs\", whereArgs);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * @param path\tThe relative path to the database on the server\n\t\t * @param path\t数据库在服务器上的相对路径\n\t\t */\n\t\tpublic static String query(String path, String table, String[] columns, String selection,\n\t\t\t\tString[] selectionArgs, String groupBy, String having,\n\t\t\t\tString orderBy, String limit) throws JSONException{\n\t\t\t\n\t\t\tJSONObject json = checkAndCreate(path, TYPE_QUERY);\n\t\t\tJsonUtils.addJSONObject(json, \"table\", table);\n\t\t\tJsonUtils.addJSONArray(json, \"columns\", columns);\n\t\t\tJsonUtils.addJSONObject(json, \"selection\", selection);\n\t\t\tJsonUtils.addJSONArray(json, \"selectionArgs\", selectionArgs);\n\t\t\tJsonUtils.addJSONObject(json, \"groupBy\", groupBy);\n\t\t\tJsonUtils.addJSONObject(json, \"having\", having);\n\t\t\tJsonUtils.addJSONObject(json, \"orderBy\", orderBy);\n\t\t\tJsonUtils.addJSONObject(json, \"limit\", limit);\n\t\t\treturn json.toString();\n\t\t}\n\t\t\n\t\t/**\n\t\t * Check the data path and generate common parameters JSONObject\n\t\t * 检查数据路径和生成共性参数的JSONObject\n\t\t */\n\t\tprivate static JSONObject checkAndCreate(String path, String type) throws JSONException{\n\t\t\tif (path == null || path.equals(\"\")) {\n\t\t\t\tthrow new NullPointerException(\"数据库所在的路径不能为空\");\n\t\t\t}\n\t\t\t\n\t\t\tJSONObject json = new JSONObject();\n\t\t\tJsonUtils.addJSONObject(json, \"path\", path);\n\t\t\tJsonUtils.addJSONObject(json, \"type\", type);\n\t\t\treturn json;\n\t\t}\n\t}\n\n\u003e JsonUtils.java：这是一个转换的工具类，包含了客户端和服务器的工具类的源码，配合上一个类使用\n\n\u003e JsonUtils.java:This is a conversion tool class, including the source of the client and server tools class, coupled with a class to use\n\n\tpackage com.hjq.mytomcat.bean;\n\t\n\timport java.util.Iterator;\n\timport java.util.Map.Entry;\n\timport java.util.Set;\n\timport org.json.JSONArray;\n\timport org.json.JSONException;\n\timport org.json.JSONObject;\n\timport android.content.ContentValues;\n\timport android.database.Cursor;\n\t/**\n\t * @author HJQ\n\t */\n\tpublic class JsonUtils {\n\t\t\n\t\t//客户端的转换工具\n\t\t//The client's conversion tool\n\t\t\n\t\t/**\n\t\t * 添加JSONObject对象\n\t\t * Add a JSONObject object\n\t\t */\n\t\tpublic static void addJSONObject(JSONObject json, String name, String string) throws JSONException{\n\t\t\tif (string != null \u0026\u0026 !string.equals(\"\")) {\n\t\t\t\tjson.put(name, string);\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * 添加JSONArray对象\n\t\t * Add a JSONArray object\n\t\t */\n\t\tpublic static void addJSONArray(JSONObject json, String name, Object[] objects) throws JSONException{\n\t\t\tif (objects != null \u0026\u0026 objects.length != 0) {\n\t\t\t\tjson.put(name, ArrayToJSONArray(objects));\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * 添加ContentValues对象\n\t\t * Add a ContentValues object\n\t\t */\n\t\tpublic static void addContentValues(JSONObject json, String name, ContentValues values) throws JSONException{\n\t\t\tif (values != null \u0026\u0026 values.size() != 0) {\n\t\t\t\tjson.put(name, ContentValuesToJSONArray(values));\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t/**\n\t\t * 数组转JsonArray\n\t\t * Array conversion to JsonArray\n\t\t */\n\t\tpublic static JSONArray ArrayToJSONArray(Object[] array) {\n\t\t\tJSONArray jsonArray = new JSONArray();\n\t\t\tfor (int i = 0; i \u003c array.length; i++) {\n\t\t\t\tjsonArray.put(array[i]);\n\t\t\t}\n\t\t\treturn jsonArray;\n\t\t}\n\t\t\n\t\t/**\n\t\t * 将ContentValues转换成JSONArray\n\t\t * ContentValues conversion to JSONArray\n\t\t */\n\t\tpublic static JSONArray ContentValuesToJSONArray(ContentValues values) throws JSONException {\n\t\t\t\n\t\t\tJSONArray jsonArray = new JSONArray();\n\t\t\tSet\u003cEntry\u003cString, Object\u003e\u003e valueSet = values.valueSet();\n\t\t\t\n\t\t\tfor(Iterator\u003cEntry\u003cString, Object\u003e\u003e iterator = valueSet.iterator(); iterator.hasNext(); ){\n\t\t\t\tEntry\u003cString, Object\u003e entry = iterator.next();\n\t\t\t\tjsonArray.put(new JSONObject().put(entry.getKey(), entry.getValue()));\n\t\t\t}\n\t\t\t\n\t\t\treturn jsonArray;\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t//服务器的转换工具\n\t\t//Server conversion tools\n\t\t\n\t\t/**\n\t\t * 获取查询的结果，将Cursor封装在Json中\n\t\t * Get the results of the query, the Cursor encapsulated in Json\n\t\t */\n\t\tpublic static String getJsonString(Cursor cursor) throws JSONException {\n\t\t\t\n\t\t\tint count = cursor.getCount();\n\t\t\t\n\t\t\tif (count \u003e 0) {\n\t\t\t\t\n\t\t\t\tJSONObject  resultJsonObject = new JSONObject();\n\t\t\t\t\n\t\t\t\tJSONArray columnNamesJsonArray = new JSONArray();\n\t\t\t\tString[] columnNames = cursor.getColumnNames();\n\t\t\t\tfor (int i = 0; i \u003c columnNames.length; i++) {\n\t\t\t\t\tcolumnNamesJsonArray.put(columnNames[i]);\n\t\t\t\t}\n\t\t\t\tresultJsonObject.put(\"columnNames\", columnNamesJsonArray);\n\t\t\t\t\n\t\t\t\tJSONArray cursorJsonArray = new JSONArray();\n\t\t\t\tJSONObject  valuesJsonObject;\n\t\t\t\t\n\t\t\t\twhile(cursor.moveToNext()){\n\t\t\t\t\tvaluesJsonObject = new JSONObject();\n\t\t\t\t\tfor (int i = 0; i \u003c columnNames.length; i++) {\n\t\t\t\t\t\tString columnName = columnNames[i];\n\t\t\t\t\t\tvaluesJsonObject.put(columnName, cursor.getString(i));\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tcursorJsonArray.put(valuesJsonObject);\n\t\t\t\t}\n\t\t\t\t//关闭cursor\n\t\t\t\tcursor.close();\n\t\t\t\t\n\t\t\t\tresultJsonObject.put(\"cursor\", cursorJsonArray);\n\t\t\t\t\n\t\t\t\treturn resultJsonObject.toString();\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t/**\n\t\t * 将JsonArray转成字符串数组\n\t\t * JsonArray conversion to array of strings\n\t\t */\n\t\tpublic static String[] JsonArrayToStringArray(JSONArray jsonArray) throws JSONException {\n\t\t\t\n\t\t\tif (jsonArray != null) {\n\t\t\t\t\n\t\t\t\tint length = jsonArray.length();\n\t\t\t\t\n\t\t\t\tif (length \u003e 0) {\n\t\t\t\t\tString[] strings = new String[length];\n\t\t\t\t\tfor (int i = 0; i \u003c length; i++) {\n\t\t\t\t\t\tstrings[i] = jsonArray.getString(i);\n\t\t\t\t\t}\n\t\t\t\t\treturn strings;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t/**\n\t\t * 将JsonArray转成ContentValues\n\t\t * JsonArray conversion to ContentValues\n\t\t */\n\t\tpublic static ContentValues JsonArrayToContentValues(JSONArray jsonArray) throws JSONException {\n\t\t\t\n\t\t\tif (jsonArray != null) {\n\t\t\t\t\n\t\t\t\tint length = jsonArray.length();\n\t\t\t\t\n\t\t\t\tif (length \u003e 0) {\n\t\t\t\t\t\n\t\t\t\t\tContentValues contentValues = new ContentValues();\n\t\t\t\t\t\n\t\t\t\t\tJSONObject jsonObject;\n\t\t\t\t\tfor (int i = 0; i \u003c length; i++) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tjsonObject = jsonArray.getJSONObject(i);\n\t\t\t\t\t\t\n\t\t\t\t\t\tJSONArray namesJSONArray = jsonObject.names();\n\t\t\t\t\t\t\n\t\t\t\t\t\tint length2 = namesJSONArray.length();\n\t\t\t\t\t\tfor (int j = 0; j \u003c length2; j++) {\n\t\t\t\t\t\t\tString name = namesJSONArray.getString(j);\n\t\t\t\t\t\t\tString value = jsonObject.getString(name);\n\t\t\t\t\t\t\tcontentValues.put(name, value);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn contentValues;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\t}\n\n\n## 请求重定向\n\n## Request to redirect\n\n\u003e 请求重定向是浏览器在访问服务器时，服务器将这个请求转到了另外一个URL地址上，所携带的路径、参数、流、请求头都会交给新的URL地址所在的服务器进行处理\n\n\u003e Request is redirect the browser when access to the server, the server will turn this request to another URL, carries path, parameters, flow, request header will be handed over to the new URL address of the server for processing\n\n\u003e 如果当前的服务器上的地址为\n\n\u003e If the current server address is\n\n\thttp://192.168.1.126:8888/\n\n\u003e 如果设置的请求重定向URL为\n\n\u003e If set the request redirection URL\n\n\thttp://192.168.1.119:8888/\n\n\u003e 访问的当前服务器URL会跳转到重定向URL\n\n\u003e Access to the current server URL will jump to redirect URL\n\n\thttp://192.168.1.126:8888/    ---\u003e    http://192.168.1.119:8888/\n\n## 字符编码\n\n## Character encoding\n\n\u003e 提供了修改字符编码的设置，你可以点击通知栏上的进入设置\n\n\u003e Provides a modified character encoding Settings, you can click on the notification bar into the set\n\n\u003e 如果你选择了某一种编码，很大程度上决定服务器解析和返回数据的所用编码\n\n\u003e If you select the one encoding, largely determine server parsing and encoding used to return data\n\n\u003e 如果你的文本里面包含中文，强烈推荐使用UTF-8为默认字符编码\n\n\u003e If your text contains Chinese, strongly recommended to use utf-8 as the default character encoding\n\n\u003e 字符编码决定了服务器解析URL和参数的编码，和你解析文本文档所用的编码格式\n\n\u003e Character encoding decided the server to parse the URL and parameters of coding, coding format used in the analytical text documents with you\n\n\u003e 字符编码至关重要，请不要设置与其无关的内容，不然会出现乱码\n\n\u003e Character encoding is critical, please don't set has nothing to do with its content, or it will appear garbled\n\n## 响应码\n\n## Response code\n\n\u003e 200：响应成功\n\n\u003e 200：Response  success\n\n\u003e 400：请求有误\n\n\u003e 400：Request is wrong\n\n\u003e 404：请求的资源不存在\n\n\u003e 404：Requested resource does not exist\n\n\u003e 412：未满足请求条件\n\n\u003e 412：Did not meet the request\n\n\u003e 500：服务器内部错误\n\n\u003e 500：Server internal error\n\n\u003e 503：服务不可用\n\n\u003e 503：Service is not available\n\n## Java 代码参考\n\n## Java Code Reference\n\n\u003e GET请求\n\n\u003e GET request\n\n\tURL url = new URL(path);\n\t\t\t\t\t\n\tHttpURLConnection conn = (HttpURLConnection) url.openConnection();\n\tconn.setRequestMethod(\"GET\");\n\tconn.setConnectTimeout(5000);\n\tconn.setReadTimeout(5000);\n\t\t\t\t\t\n\tconn.connect();\n\t\t\t\t\t\n\tint responseCode = conn.getResponseCode();\n\tif (responseCode == 200) {\n\t\t//System.out.println(conn.getHeaderFields());\n\t\t\t\t\t\t\n\t\tInputStream is = conn.getInputStream();\n\t\tString text = getTextFromStream(is);\n\t\tSystem.out.println(text);\n\t}\n\n\u003e POST请求\n\n\u003e POST request\n\n\tURL url = new URL(path);\n\tHttpURLConnection conn = (HttpURLConnection) url.openConnection();\n\tconn.setRequestMethod(\"POST\");\n\tconn.setConnectTimeout(5000);\n\tconn.setReadTimeout(5000);\n\t\n\tconn.setDoOutput(true);\n\tOutputStream os = conn.getOutputStream();\n\tos.write(data.getBytes());\n\t\n\tconn.connect();\n\n\tint responseCode = conn.getResponseCode();\n\n\tif (responseCode == 200) {\n\t\t//System.out.println(conn.getHeaderFields());\n\t\t\n\t\tInputStream is = conn.getInputStream();\n\t\tString text = getTextFromStream(is);\n\t\tSystem.out.println(text);\n\t}\n\n\u003e 上传文件\n\n\u003e Upload file\n\n\tURL url = new URL(path);\n\tHttpURLConnection conn = (HttpURLConnection) url.openConnection();\n\tconn.setRequestMethod(\"POST\");\n\tconn.setConnectTimeout(5000);\n\tconn.setReadTimeout((int) (file.length() / 128 + 2048));\n\t\n\tconn.setRequestProperty(\"Content-Disposition\", \"attachment;filename=\" + URLEncoder.encode(fileName, charsetName));\n\tconn.setRequestProperty(\"Content-Length\", file.length() + \"\");\n\tconn.setRequestProperty(\"Content-MD5\", MD5Utils.getFileMD5(file.toString()));\n\t\n\tconn.setDoOutput(true);\n\t\n\tOutputStream out = conn.getOutputStream();\n\t\n\tFileInputStream in = new FileInputStream(file);\n\tint count;\n\tbyte[] buffer = new byte[1024];\n\twhile ((count = in.read(buffer)) != -1) {\n\t\tout.write(buffer, 0, count);\n\t\tout.flush();\n\t}\n\tin.close();\n\tout.close();\n\t\n\tconn.connect();\n\t\n\tint responseCode = conn.getResponseCode();\n\n\tif (responseCode == 200) {\n\t\t//System.out.println(conn.getHeaderFields());\n\t\t//System.out.println(URLDecoder.decode(conn.getHeaderFields().get(\"Content-Disposition\").get(0), charsetName));\n\n\t\tSystem.out.println(conn.getHeaderFields().get(\"Content-MD5\").get(0));\n\t}\n\n\u003e 操作SQLite数据库\n\n\u003e SQLite database operation\n\n\tURL url = new URL(path);\n\tHttpURLConnection conn = (HttpURLConnection) url.openConnection();\n\tconn.setRequestMethod(\"POST\");\n\tconn.setConnectTimeout(5000);\n\tconn.setReadTimeout(5000);\n\t\n\tconn.setDoOutput(true);\n\tOutputStream os = conn.getOutputStream();\n\tos.write(text.getBytes());\n\t\n\tconn.connect();\n\t\n\tint responseCode = conn.getResponseCode();\n\n\tif (responseCode == 200) {\n\t\tInputStream in = conn.getInputStream();\n\t\tString json = getTextFromStream(in);\n\n\t\tSystem.out.println(json);\n\t}\n\n\u003e 将字节读取流转换成文本的工具类，客户端需要指定字符编码\n\n\u003e To circulate the bytes read into the text tool, the client need to specify the character encoding\n\n\tpublic String getTextFromStream(InputStream in) throws IOException \n\t{\n\t\tbyte[] b = new byte[1024];\n\t\tint len = 0;\n\t\tByteArrayOutputStream bos = new ByteArrayOutputStream();\n\t\twhile((len = in.read(b)) != -1){\n\t\t\tbos.write(b, 0, len);\n\t\t}\n\t\tString text = new String(bos.toByteArray(), charsetName);\n\t\treturn text;\n\t}\n\n\u003e 若你有任何疑问或反馈，可以发邮件到880634@qq.com\n\n\u003e If you have any queries or feedback, you can send email to jinqun0730@gmail.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetactivity%2Fmytomcat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetactivity%2Fmytomcat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetactivity%2Fmytomcat/lists"}