Java MVC 和 Rest 服务器以及 JavaScript 重客户端
我正在开始开发基于网络的用户界面,并正在寻找一些专家建议来确定我的项目的正确方向。
由于我们的服务器端将使用 Java 进行开发,因此我计划使用无脚本 JSP 和一个名为 FrontMan 的 MVC 框架。 FrontMan是一个类似于Struts的基于Java的轻量级MVC框架。我玩过它并且喜欢它。该计划是使用由 JSTL 和 JSP 标记文件辅助的无脚本 JSP。我使用这些技术制作了一些原型,我喜欢我所拥有的。
现在我正在规划客户端的内容。我的计划是使用 JavaScript、jQuery、jQuery UI 来构建前端。在我的调查过程中,我发现了一个非常漂亮的 JavaScript MVC 框架,名为 JavaScriptMVC。我不得不说我真的很喜欢它。它不仅仅是一个客户端 MVC 框架,还包括用于测试、记录和部署的工具。
我越深入地研究客户端计划,我意识到我认为这将更像是一个 JavaScript(客户端)应用程序。我倾向于在 JavaScript 中完成尽可能多的工作,而不是通过 Java 在后端完成。后端主要用于与数据库通信并响应客户端(前端)的请求以操作或检索数据。
我对 RESTful Web 服务相当陌生,但根据我对它们的了解,我认为这可能是开展该项目的一个好方向。
我想知道如何同时使用 MVC 框架和 REST 框架?它们放在一起有意义吗?
我使用 Jetty 作为我的 Web 服务器,所以我认为这适合使用 Restlet...?
不管怎样,我不确定这篇文章有多大意义,所以我现在就到此为止。
I am in the process of beginning development of a web-based user interface and am looking for some expert advice on the right direction for my project.
Since our server-side is to be developed using Java, I am planning to use scriptless-JSP and an MVC framework called FrontMan. FrontMan is a lightweight Java-based MVC framework similar to Struts. I have played around with it and like it. The plan is to use scriptless-JSP assisted by JSTL and JSP tag files. I worked out some prototypes using these technologies and I liked what I had.
Now I am in the process of planning out the client-side stuff. My plan is to use JavaScript, jQuery, jQuery UI to build the front end. During my investigation I came across a very nifty JavaScript MVC framework named JavaScriptMVC. I have to say I really like it. It is not just a client-side MVC framework, but also includes tools for testing, documenting and deploying.
The more I engage in figuring out the client-side plan, I realize that I think this is going to be more of a JavaScript (client-side) app. I am leaning towards doing as much of the work in JavaScript rather than on the backend via Java. The backend will exist mostly for communicating with the database and responding to requests from the client (frontend) for manipulating or retrieving data.
I am rather new to RESTful web services, but in the little I have read about them, I think this might be a good direction to take this project.
I am wondering how I can employ both an MVC framework and REST framework together? Do they make sense together?
I am using Jetty as my web server, so I think that lends itself to using Restlets...?
Anyway, I am not sure how much sense I am making in this post, so I will stop it there for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如之前的海报所提到的,这是完全有道理的。 MVC 允许您分离关注点,以便您可以将应用程序逻辑与表示逻辑分开。
您的 REST 控制器服务您需要的请求,填充模型,并以类似 REST 的方式公开它,通常是通过向用户返回 xml 视图。这可以通过许多库(例如 xstream、jaxb、castor、xmlbeans)来帮助,它们都提供将对象编组到 xml 的例程。
As the previous poster mentioned, it makes perfect sence. MVC let's you separate concerns such that you can keep your application logic separate from your presentational logic.
Your REST controller serves the request you need, populates the model, and exposes it in a REST like manner, typically by returning an xml view to the user. This can be aided by a number of libraries such as xstream, jaxb, castor, xmlbeans, which all provides routines to marshall an object into xml.
在服务器端公开 REST API 将非常适合您的 JS 前端。您的资源必须公开 JSON 表示形式。您甚至可以从其他客户端(例如手机)重用此 Web API。
作为 Restlet Framework 的领导者,我只能推荐它用于此目的。与 Jetty 的集成非常稳定:)
干杯,
杰罗姆
Exposing a REST API on the server-side will be a perfect fit for your JS front-end. Your resources will have to expose JSON representations. You will even be able to reuse this web API from other clients such as mobile phones.
As the lead for the Restlet Framework, I can only recommend it for this purpose. Integration with Jetty is very stable :)
Cheers,
Jerome
关于此问题的相当广泛的讨论也可以在这里找到:
独立的 REST JSON API 服务器和客户端?
对我来说这非常有帮助。
A quite extensive discussion on this can also be found here:
Separate REST JSON API server and client?
For me it was very helpful.
是的! Johan Sjöberg 说的很有道理!例如,您可以使用 Spring MVC。我非常喜欢它,认为它非常简单易学。 此处有一个示例。
顺便说一句,对于前端,您可能想查看此演示文稿。
Yes! It makes sense as Johan Sjöberg said! You can use Spring MVC for example. I like it a lot and think it is very simple and easy to learn. You have an example here.
By the away, for the frontend maybe you would like to check this presentation.