HttpServletResponse返回JSON数据

@WebServlet("/demo")
public class demo extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    public demo() {
        super();
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write(JSONObject.toJSONString(data()));
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    
    private HashMap<String, String> data() {
        HashMap<String, String> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            map.put("key" + i, String.valueOf(i));
        }
        return map;
    }
}

- 阅读全文 -

Python使用阿里接口查询域名是否注册

import urllib.request
domain = "fluorine.xyz"
req = urllib.request.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=' + domain)
result = req.read().decode()
if ('<original>211' in result):
    print(domain + ' 已注册')
elif ('<original>210' in result):
    print(domain + ' 未注册')
else:
    print('error')

- 阅读全文 -

Java输出26个字母任意3字母所有组合(包含重复)

/**
 * 输出26个字母任意3字母所有组合(包含重复)
 * @author fluorine.xyz
 */
public class Print {
    public static void main(String[] args) {
        // 两个数组
        String [] one = new String [26];
        String [] two = new String [26];
        String [] three = new String [26];
        for (int i = 0; i < 26; i++) {
            one[i] = String.valueOf((char)(96 + i + 1));
            two[i] = String.valueOf((char)(96 + i + 1));
            three[i] = String.valueOf((char)(96 + i + 1));
        }
        for (int i = 0; i < one.length; i++) {
            for (int j = 0; j < two.length; j++) {
                for (int k = 0; k < three.length; k++) {
                    System.out.print(one[i] + two[j] + three[k] +",");
                }
            }
        }
    }
}

- 阅读全文 -

解决JDK-12没有JRE的方法

- 阅读全文 -

计算两个时间的日、周间隔差

- 阅读全文 -