简体   繁体   English

GWT 无 RPC 的数据库访问

[英]GWT database-access without RPC

I'm using GWT for a web-app and I need to access to a mySql-database.我将 GWT 用于 Web 应用程序,我需要访问 mySql 数据库。 There will be only one client (The app is used on a iPad localy).将只有一个客户端(该应用程序在 iPad 本地使用)。 Is there any way to access the database without RPC?有没有什么方法可以在没有RPC 的情况下访问数据库? I'm looking for a possibility to direkty query a database.我正在寻找一种直接查询数据库的可能性。

Thanks!谢谢!

There are 2.5 reasons you cannot use gwt to directly access MySQL.不能使用 gwt 直接访问 MySQL 有 2.5 个原因。

Reason #1.原因#1。 GWT is compiled into Javascript. GWT 编译成 Javascript。 You need to open a socket to the database server.您需要打开一个到数据库服务器的套接字。 GWT does not allow you to open a socket. GWT 不允许您打开套接字。 In fact, no unaugmented browser (before advent of html5) is able to open a socket.事实上,没有未增强的浏览器(在 html5 出现之前)能够打开套接字。 But you can open a socket using Flash actionscript, or HTML 5 javascript.但是您可以使用 Flash actionscript 或 HTML 5 ZDE9B9ED78D7E2E1DCEEFFEE780E2F9 打开一个套接字

Reason #2.原因 #2。 OK, let's say you used HTML5 sockets.好的,假设您使用了 HTML5 sockets。 And you spent 6 months writing in Javascript a JDBC connectivity.你花了 6 个月时间编写 Javascript 和 JDBC 连接。 But, your websocket would still need to address a servlet on the server which would help your websocket establish a persistent connection - and mysql is unable to perform such an establishment.但是,您的 websocket 仍需要解决服务器上的 servlet,这将帮助您的 websocket 建立持久连接 - 而 mysql 无法执行此类建立。

Reason #3.原因#3。 SLD - SOP restriction: (Second Level Domain Same Origin Policy) Standard browser restricts its pages to only be able to request for, and to include, content from within the same second-level domain (SLD) as the server that provided that page to the browser. SLD - SOP 限制:(二级域同源策略)标准浏览器将其页面限制为只能请求和包含来自与提供该页面的服务器相同的二级域 (SLD) 内的内容浏览器。 Top level domains (and top-level and a half) are such as.com, .org, .net, .me.us or.co.uk.顶级域(以及顶级半域)例如.com、.org、.net、.me.us 或.co.uk。 So, domain names such as google.com, fbi.gov, mit.edu are second level domains.因此,google.com、fbi.gov、mit.edu 等域名属于二级域名。 While, mail.google.com would be a third-level domain.而 mail.google.com 将是一个三级域。 Therefore, GWT would work only within the confines of an SLD.因此,GWT 只能在 SLD 范围内工作。 Your web server must also be accessible at the same SLD as your mysql server.您的 web 服务器还必须可以在与 mysql 服务器相同的 SLD 上访问。

SLD-SOP and tunneling requirement is to close a security hole that could have allowed any tom-rick-or-mary to log into your system thro your browser. SLD-SOP 和隧道要求是关闭一个安全漏洞,该漏洞可能允许任何汤姆里克或玛丽通过您的浏览器登录到您的系统。 Tunneling is always required for a browser to connect to a server other than a http server.浏览器始终需要隧道连接到 http 服务器以外的服务器。 Tunneling is when a browser exploits the web server as a yenta (yiddish for busy-body/go-between/match-maker) to get to another server.隧道是当浏览器利用 web 服务器作为日元(意第绪语为忙体/中间人/媒人)到达另一台服务器时。

You have no choice but to use GWT-RPC.您别无选择,只能使用 GWT-RPC。 Perhaps you don't wish to use RPC, then you could use RequestBuilder, or Script-Include or RequestFactory.也许您不想使用 RPC,那么您可以使用 RequestBuilder、Script-Include 或 RequestFactory。 But they are all still diverse means of tunneling.但它们仍然是多种隧道挖掘方式。 http://h2g2java.blessedgeek.com/2011/06/gwt-requestbuilder-vs-rpc-vs-script.html . http://h2g2java.blessedgeek.com/2011/06/gwt-requestbuilder-vs-rpc-vs-script.html

There is one reason why you can connect to your database server from your gwt client: Your database server must run httpd connection engine.您可以从 gwt 客户端连接到数据库服务器的原因之一:您的数据库服务器必须运行 httpd 连接引擎。 That is, your gwt app would access the db server thro http.也就是说,您的 gwt 应用程序将通过 http 访问数据库服务器。 I am not familiar with which relational database has a http access available.我不熟悉哪个关系数据库具有可用的 http 访问权限。 Most probably, you would have to query thro xml or json.最有可能的是,您必须查询 xml 或 json。

However, a company I had worked for created our own http service to allow "direct" client access.但是,我曾供职的一家公司创建了我们自己的 http 服务,以允许“直接”客户端访问。 "direct" is a misnomer because we used tomcat. “直接”是用词不当,因为我们使用了 tomcat。 It is stil tunneling.它仍然是隧道。 Any database company that offers "direct" http access is still tunneling.任何提供“直接”http 访问的数据库公司仍在隧道中。 Tunneling - no escape from it.隧道 - 无处可逃。

You could augment the browser with Flash and write a Flash application rather than using GWT.您可以使用 Flash 扩充浏览器并编写 Flash 应用程序,而不是使用 GWT。 If direct access is so essential to you, you would have to abandon GWT and develop in Flash and run a httpd engine for your database server.如果直接访问对您来说非常重要,您将不得不放弃 GWT 并在 Flash 中开发并为您的数据库服务器运行 httpd 引擎。

GWT is ultimately Javascript. GWT 最终是 Javascript。 As noted at Are there JavaScript bindings for MySQL?如在是否存在 MySQL 的 JavaScript 绑定? , there is currently no way of accessing MySQL from Javascript. ,目前无法从 Javascript 访问 MySQL。

Therefore you can't access it from client-side GWT code.因此,您无法从客户端 GWT 代码访问它。

AFAIK it's not possible, and even if it were, it would be a really bad idea. AFAIK 这是不可能的,即使是这样,这也将是一个非常糟糕的主意。 Are you sure you actually need a database?你确定你真的需要一个数据库吗? Maybe something like gwt-client-storage would be more appropriate.也许像gwt-client-storage这样的东西会更合适。

EDIT编辑

Your database would we publicly accessible and open for any sort of attacks.您的数据库将被我们公开访问并针对任何类型的攻击开放。

EDIT 2编辑 2

This may even be a better solution, as it offers support for accessing the HTML5 Database API and is targeted to iPhone/iPad.这甚至可能是一个更好的解决方案,因为它支持访问 HTML5 数据库 API 并且针对 iPhone/iPad。

gwt-mobile-webkit gwt-mobile-webkit

If you were even successful in doing so, in short, doing a CTRL + U on the browser would make your database name, username, password, tables names etc visible... And done, any developer curious to know your code has a way to hack anything and everything in your server.如果您甚至成功地这样做了,简而言之,在浏览器上执行 CTRL + U 将使您的数据库名称、用户名、密码、表名等可见...完成,任何想知道您的代码的开发人员都有办法破解服务器中的任何东西。

I think it's not possible, I mean, if you want all your data stored in DBs.我认为这是不可能的,我的意思是,如果您希望所有数据都存储在数据库中。 I mean, GWT compiles into javascript and javascript executes on the client (typically a web browser).我的意思是,GWT 编译成 javascript 和 javascript 在客户端上执行(通常是 Z2567A5EC9705EB7AC2C984033E)。

If you want to access data stored somewhere (by some mean) in a server, then you have no option but RPC.如果您想访问存储在服务器中某处(以某种方式)的数据,那么您别无选择,只能使用 RPC。 If I were you, I would stop thinking in client-server paradigm (GWT was developed with that in mind).如果我是你,我会停止思考客户端-服务器范式(GWT 的开发就是考虑到这一点)。 Perhaps some embedded database like H2 and then hold connections through JDBC.也许像 H2 这样的嵌入式数据库,然后通过 JDBC 保持连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM