servlet 解决ajax跨域问题以及接收ajax的字符串参数

解决跨域问题

response.setHeader("Access-Control-Allow-Origin", "*");

接收ajax的字符串参数

        StringBuilder buffer = new StringBuilder();
        BufferedReader reader = request.getReader();
        String line;
        while ((line = reader.readLine()) != null) {
            buffer.append(line);
        }
        String data = buffer.toString();

        System.out.println(data);

你可能感兴趣的:(java,Ajax,servlet)