brody1994 / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

try to add localhost:8080/h2console/console/q.do to return json ResultSet #575

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I want to get json ResultSet in h2console (Have a look at 2 attachments). 
When I start h2 Server in Eclipse, it works well!  reqdo.responseText is 
["id":1,"test":"hi"]
but 
> build.bat warConsole
when I put bin/h2console.war to 
E:\glassfish4.0\glassfish\domains\domain1\autodeploy, it FAILED! 
reqdo.responseText is the content of error.jsp

Why? How can I  get json ResultSet in h2console.war?

jsessionid='0467b5de35eeaac5774c9b7ad668359d'
url="http://localhost:8080/h2console/console/q.do?jsessionid="+jsessionid;
            reqdo = new XMLHttpRequest();
            reqdo.open("POST", url, false);
            reqdo.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            reqdo.setRequestHeader("Accept", "application/json");
            sql="SELECT * FROM test ";

            reqdo.send("sql="+encodeURIComponent(sql));
            console.log(reqdo.responseText)

1. modify WebApp.java
----
private String q() {
... ...
  if (rs != null) {result = convertResultSetToJson(rs);}
  session.put("result", result);
....
  return "jsonResult.jsp";
}
----

} else if ("q.do".equals(file)) {
                file = q();

----
if ("q.do".equals(file))
                mimeType = "application/json";

2. add a file /h2/src/main/org/h2/server/web/res/jsonResult.jsp

Original issue reported on code.google.com by Avv...@gmail.com on 29 Jul 2014 at 7:01

Attachments:

GoogleCodeExporter commented 9 years ago
I don't understand. You did something, and it failed. Is this a bug in H2? 

Original comment by thomas.t...@gmail.com on 29 Jul 2014 at 7:06

GoogleCodeExporter commented 9 years ago
not a bug!
just try to query h2 db (by http) and get json result in h2console.war
I think it is very useful

Original comment by Avv...@gmail.com on 30 Jul 2014 at 9:21

GoogleCodeExporter commented 9 years ago
Ah, so it's a patch for new feature?

Original comment by thomas.t...@gmail.com on 30 Jul 2014 at 10:27