Struts网页应用与React

huangapple go评论84阅读模式
英文:

Struts web application with React

问题

我之前一直在使用带有 React UIASP.Net 应用程序,我很喜欢我所看到的。

我主要开发使用的是 Java + Struts。我在想,是否有人有将这两者结合的经验?它们能一起工作吗?这是否值得努力,还是它们是两个独立的部分。

英文:

I was working with an ASP.Net application with a React UI for a while, and I liked what I saw.

My main development is Java + Struts. I'm wondering, does anyone have any experience combining the two? Can they work together, is it worth the effort, or are they 2 separate beasts.

答案1

得分: 2

首先,我并不完全清楚您的问题是什么,但如果您期望在使用ReactJs和Struts构建Web应用程序时获得一些答案,简单的答案显然是可以的,

实现您的Struts API,该API仅返回数据,然后编写ReactJs组件来使用相同的数据。

然而,这与使用struts + JSP略有不同。

通常,Struts + JSP在后端执行HTML模板化。因此,数据被注入到服务器上的HTML中,而HTML也是从服务器返回的格式。

React是一个客户端HTML模板化库。因此,它通过AJAX调用与服务器通信,并读取数据(以JSON或其他格式)并使用React在客户端注入数据。因此,从Web应用程序架构的角度来看,这是一个巨大的转变。

在Struts2中,您可以通过struts2-rest-plugin实现RESTful API。这篇文章将帮助您对此有一些了解
https://www.concretepage.com/struts-2/struts-2-rest-web-service-integration-example

顺便说一下,问题是,当Spring Boot在基于Java的Web开发中发挥重要作用时,是否真的值得花时间在struts上。

英文:

First of all, I'm not crystal clear about what you are asking,
But if you expecting some answer for building a web application with ReactJs and Struts, the simple answer is obviously we can build,

Implement your Struts APIs that return only data, then write ReactJs components to consume the same.

However, it will be a little more different than working with struts + JSP.

Usually, Struts + JSP is doing HTML templating on the back-end. So data are injected into HTML on server and HTML is also the format that is returned from the server.

React is client-side HTML templating library. So it is expected to communicate with the server via AJAX calls and reading data (in JSON or other formats) and inject that data on the client using React. So This is a huge shift from the web application architecture point of view.

In Struts2 you can implement RESTful API via struts2-rest-plugin. This article will help you get some idea about it
https://www.concretepage.com/struts-2/struts-2-rest-web-service-integration-example

Btw the thing is, Is it really worth spending time for struts while Spring boot playing a major role in java based web development.

huangapple
  • 本文由 发表于 2020年8月18日 05:15:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63458751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定