5 import java.security.NoSuchAlgorithmException;
8 import com.sun.net.httpserver.HttpExchange;
9 import com.sun.net.httpserver.HttpHandler;
10 import com.sun.net.httpserver.HttpServer;
13 public class httpget implements Runnable {
17 public static Map<String, String> splitQuery(String query) throws UnsupportedEncodingException
19 Map<String, String> query_pairs = new LinkedHashMap<String, String>();
20 String[] pairs = query.split("&");
21 for (String pair : pairs)
23 int idx = pair.indexOf("=");
24 query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
32 HttpServer server = HttpServer.create(new InetSocketAddress(global.portaHttpServer), 0);
33 server.createContext("/test", new MyHandler());
34 server.setExecutor(null); // creates a default executor
36 } catch (IOException e) {
41 static class MyHandler implements HttpHandler
43 public void handle(HttpExchange t) throws IOException
45 URI req=t.getRequestURI();
46 String query=req.getQuery();
47 Map<String, String> result=splitQuery(query);
48 String id=result.get("id");
52 String returnQuery=global.request.dbQuery("3"+id);
53 t.sendResponseHeaders(200, returnQuery.length());
54 OutputStream os = t.getResponseBody();
55 os.write(returnQuery.getBytes());
57 } catch (ClassNotFoundException e) {
59 } catch (SQLException e) {
61 } catch (InstantiationException e) {
63 } catch (NoSuchAlgorithmException e) {
65 } catch (IllegalAccessException e) {