I'm quite used to PHP and have just started working with Java server side scripting. I've been told that it's bad practice to use scriptlets but I've used them anyway for testing purposes.
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.net.*"%>
<%
String url = "https://www.google.com/recaptcha/api/siteverify";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "USER_AGENT");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = "secret=6LeI6AgTAAAAAGJDs5rvWB67-d7n5YjN61JW1RKn&response="
+request.getParameter("g-recaptcha-response");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
out.println("\nSending 'POST' request to URL : " + url);
out.println("Post parameters : " + urlParameters);
out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer responses = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
responses.append(inputLine);
}
in.close();
out.println(responses.toString());
%>
Here the content is not really relevant to the question.I needed a way to parse the json response which is quite simple using json_decode() in PHP .
I have downloaded JSONObject.java, JSONString.java ... and all the java files given at http://www.json.org/java/index.html .
Is there any way I could include these java files so I could use the classes available in these java files?
I assumed it would be along the lines of :
<%@page import="JSONArray.*"%>