server.createContext("/test", new MyHandler());
server.setExecutor(null); // creates a default executor
server.start();
- }catch (Exception e)
- {
+ } catch (IOException e) {
e.printStackTrace();
}
- }
+ }
static class MyHandler implements HttpHandler
{
public void handle(HttpExchange t) throws IOException
{
-
- /*String response = "This is the response";
- System.out.println("mannaggia santa");
- t.sendResponseHeaders(200, response.length());
- OutputStream os = t.getResponseBody();
- os.write(response.getBytes());*/
URI req=t.getRequestURI();
String query=req.getQuery();
Map<String, String> result=splitQuery(query);
String id=result.get("id");
- //System.out.println(id);
try
{
- dbConnect request=new dbConnect();
- String returnQuery=request.dbQuery("3"+id);
+
+ String returnQuery=global.request.dbQuery("3"+id);
t.sendResponseHeaders(200, returnQuery.length());
OutputStream os = t.getResponseBody();
os.write(returnQuery.getBytes());
os.close();
- }
- catch(SQLException e)
- {}
- catch(ClassNotFoundException c)
- {}
- catch(IllegalAccessException a)
- {}
- catch(InstantiationException i)
- {} catch (NoSuchAlgorithmException e) {
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
e.printStackTrace();
}
}