Search code examples
javareactjsjspstruts

Struts web application with React


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.


Solution

  • 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.