简体   繁体   English

如何存储Java applet的数据

[英]How to store data for a java applet

I have to create a java applet that needs to access static data which is around 600k in size. 我必须创建一个需要访问大小约为600k的静态数据的Java applet。 This data is exported from an sql database. 此数据从sql数据库导出。 What is the the best format for that data to be stored in (xml, json, java include file), to get fastest/easiest access to it. 存储在(xml,json,java包含文件)中的数据的最佳格式是什么,以获得最快/最简单的访问权限。 I am a complete java noob and this question might be stupid, but is there a way to 'compile' this data in to executable so there are no additional requests to server once the applet is loaded. 我是一个完整的java菜鸟,这个问题可能很愚蠢,但有没有办法将这些数据“编译”成可执行文件,因此一旦加载applet就没有其他请求服务器。 Thanks in advance! 提前致谢!

I do not know what do you mean when you mention 'java include file'. 当你提到'java include file'时,我不知道你是什么意思。

All the rest is OK. 其余的都没关系。 You can use either XML or JSON. 您可以使用XML或JSON。 It depends on your needs and taste. 这取决于您的需求和口味。 Just remember that JDK has built-in tools to parse XML and does not have such tools for JSON, so you will have to add external dependency (eg GSON). 请记住,JDK具有解析XML的内置工具,并且没有用于JSON的此类工具,因此您必须添加外部依赖项(例如GSON)。 Generally it is not a problem but sometimes code size may be important for applets that are expected to be downloaded from server to client. 通常,这不是问题,但有时代码大小对于预期从服务器下载到客户端的小程序可能很重要。

The other problems with applets is that unsigned applet cannot write to client's disk. applet的其他问题是unsigned applet无法写入客户端的磁盘。 So, whatever format you choose you have to store the information somewhere. 因此,无论您选择何种格式,都必须将信息存储在某处。 You can store it on server, but server has access to DB anyway, so why to create copy? 您可以将其存储在服务器上,但无论如何服务器都可以访问数据库,那么为什么要创建副本呢?

So, my suggestion is the following. 所以,我的建议如下。 Store data in database. 将数据存储在数据库中 Create server side component (web service) that allows your applet to access the data. 创建允许applet访问数据的服务器端组件(Web服务)。 Applet should store in browser cookies user id, so next time user runs the applet it enters automatically. Applet应该存储在浏览器cookie用户ID中,因此下次用户运行applet时会自动进入。

To access browser cookie from applet user live connect and remember that applet tag should have MAYSCRIPT attribute. 要从applet用户实时连接访问浏览器cookie,请记住applet标签应具有MAYSCRIPT属性。

If the data is static, just copy in the source tree next to your .java files. 如果数据是静态的,只需复制.java文件旁边的源代码树即可。

From there, you can access it (from a class in the same package) with: 从那里,您可以访问它(来自同一包中的类):

getClass().getClassLoader().getResourceAsStream("name");

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

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