将 JSP 与 AngularJS 集成,在现实世界中是否值得关注? [英] Integrating JSP with AngularJS, Is it a concern in real world?

查看:26
本文介绍了将 JSP 与 AngularJS 集成,在现实世界中是否值得关注?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习 Angular JS 的方向是否正确?

Am I going in a right direction of learning Angular JS?

我是 AngularJS 的新手,但设法运行了一个包含 AngularJS 代码的 jsp 文件,并进行了测试计算/加法,效果很好.

I'm new to AngularJS but managed to run a jsp file which contain AngularJS code, and made a test calculation/addition and it worked good.

后来当我搜索网络论坛时,我才知道它们不应该一起工作,因为这会引起麻烦.

Later when I search web forums, I came to know they are both not supposed to work together as it can cause trouble.

我使用过 netbeans 和 GlassFish Server.

I've used netbeans and GlassFish Server.

推荐答案

我不会将 Servlet/JSP 技术与 SPA(单页应用程序......在您的情况下由 angular 驱动)混合使用.您可以做的是使用像 SpringMVC(或 Jersey)这样的工具,它有一个 JSP,您的角度驱动的 SPA.这样你就可以对初始响应中的初始 HTML/JS/CSS 负载进行大量控制.一旦加载了应用程序",它与服务器的所有通信都是通过 XHR 调用($http 或 $resource 的角度)完成的.Spring 使使用 @Controller 创建它变得非常简单,并为您提供所需的所有灵活性......诸如 spring 安全性和依赖注入之类的东西.

I wouldn't mix a Servlet/JSP tech with an SPA (single page app....driven by angular in your case). What you can do is use a tool like SpringMVC (or Jersey) that has a single JSP which is your angular driven SPA. That way you have lots of control over the initial HTML/JS/CSS payload in the initial response. Once that "app" is loaded, all it's communication with the server is done via XHR calls ($http or $resource in angular). Spring makes this pretty simple to create using @Controller and giving you all the flexibility you need... things like spring security and dependency injection.

我一直在业余时间做一些像这样简单的事情,以帮助 Java 服务器端的人们进入 Angular.

I've been working in my spare time on something simple just like this to help java server side people get into Angular.

这个想法是你有一个控制器,当你向 GET 请求时返回一个 JSP

the idea is that you'd have a controller that returns a JSP when you make a GET request to

http://your.site.com/contextRoot

那个页面会有 JS/CSS 链接来加载 Bootstrap/JQuery/Angular/Whatever...从那里角度路由器会启动,你的 URL 可能会像这样结束

That page would have the JS/CSS links to load Bootstrap/JQuery/Angular/Whatever... From there the angular router would kick in and your URL might end up like this

http://...../contextRoot#home

在客户端和服务器上运行 angular 的 JSP 之间的所有通信都是通过 $http 调用完成的,您可以在 Spring 中创建控制器来处理所有这些.

All communication between the JSP running angular on the client and the server is done with $http calls and you can make controllers in Spring to handle all this.

一旦我的Springular"应用可用,我就会在这里发帖

I'll post back here once I have my "Springular" app available

这篇关于将 JSP 与 AngularJS 集成,在现实世界中是否值得关注?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆