简体   繁体   English

JAVA Client-Server应用程序与XML通信

[英]JAVA Client-Server application communicating with XML

I'm making a question/answer application , kinda like stack-overflow but as a desktop app for a uni project(not asking to do my work for me though , ive done a good part so far). 我正在制作一个问题/答案应用程序,有点像堆栈溢出,但是作为uni项目的桌面应用程序(尽管我不要求自己做我的工作,到目前为止,我已经做得很好)。

The questions,answers,users and comments are all stored in XML files rather than a SQL databse. 问题,答案,用户和注释都存储在XML文件中,而不是SQL数据库中。

Now i have my XMLParser working with DOM , i made all of the needed functions like 现在,我将XMLParser与DOM一起使用,并完成了所有所需的功能,例如

 - User getUserById()
 - ArrayList<Comment> getCommentsByQid()

and so on ... 等等 ...

Also done the interface which is similar to this web page but as a java application, all working so far. 还完成了与该网页相似的界面,但作为Java应用程序,到目前为止都可以使用。

How the interface looks isnt at all part of the project . 界面的外观在项目的所有部分都不重要。

The problem is teacher just told us that the files shouldn't be stocked nor treated locally (logical he never asked for it :/), and that i should make all these functions treated by a server which then parses the XML files and then reports the result to the application in XML format so that the application can go ahead and display the info ... 问题是老师刚刚告诉我们,不应在本地存储或处理文件(逻辑上他从来没有要求过:/),我应该让服务器处理所有这些功能,然后服务器解析XML文件,然后报告结果以XML格式发送给应用程序,以便应用程序可以继续显示信息...

Well i know socket programming but re-doing things at this low level would take me forever, and after asking around i learned that it should be easily done since i have the functions ready , and that Netbeans (which im using) has servers like that ... 好吧,我知道套接字编程,但是以这种低水平进行操作会花我一辈子的时间,在问了一下之后,我了解到应该容易完成,因为我已经准备好了功能,并且Netbeans(我正在使用)具有这样的服务器...

So what id have to do is make the application request something from the server application , like "get all questions tagged java" , the server then calls getQuestionsByTag("java") which i already written, and returns the result as XML ... what is it that im looking for here ? 因此,id要做的就是使应用程序从服务器应用程序请求某些内容,例如“获取所有标记为Java的问题”,然后服务器调用我已经编写的getQuestionsByTag(“ java”),并将结果返回为XML。我在这里找什么? HTTP server ? HTTP服务器? apache ? 阿帕奇? a service ? 服务? ... link to any good tutorial would do . ...链接到任何好的教程都可以。

Solved ... the keyword was SOAP . 解决了...关键字是SOAP。 I followed this tutorial here 在这里遵循了本教程

The way it works is the Server and Client define the way they want to communicate with WSDL which is a way to envelop an Object in XML format to send as an XML request/response . 它的工作方式是服务器和客户端定义他们想与WSDL通信的方式,这是一种将XML格式的对象封装为XML请求/响应的方式。 The Server/Client then knows how to convert that message back into a JAVA Object since they agreed on the format in the first place . 服务器/客户端然后知道如何将消息转换回JAVA对象,因为他们首先就格式达成了一致。

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

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