javascript - How do I rewrite struts application which returns jsp pages using react? - Stack Overflow

admin2025-04-18  0

I have a web service written in Java using Struts2, struts controller returns jsp pages, now I want to rewrite frontend using react ponents, what is the best way to start?

I have a web service written in Java using Struts2, struts controller returns jsp pages, now I want to rewrite frontend using react ponents, what is the best way to start?

Share Improve this question edited May 4, 2017 at 17:49 luboskrnac 24.6k10 gold badges86 silver badges93 bronze badges asked May 4, 2017 at 9:46 ThinkGeekThinkGeek 5,16716 gold badges50 silver badges101 bronze badges 3
  • 1 Implement your APIs that return only data, then write ponents to consume the same. – Dave Newton Commented May 4, 2017 at 10:38
  • Ya it sounds like a feasible approach to start with. One follow up question on this: Do you think after such migration there wont be a need of struts layer all together at the server end? – ThinkGeek Commented May 8, 2017 at 5:43
  • Also what is your remended framework to write APIs, considering server code(Buisness Logic, DAOs etc) is written in Java. Something which does not a involve a lot of rewrite and still can give me a way forward to manage my application without introducing unnecessary bridges to glue everything together. – ThinkGeek Commented May 8, 2017 at 6:10
Add a ment  | 

1 Answer 1

Reset to default 7

TLDR, you can easily announce to your stakeholders, that it'll take few months/year or more depending on how big is your application/team.

This is huge shift from web application architecture point of view. Struts2 + JSP is doing HTML templating on back-end. So data are injected into HTML on server and HTML is also format that is returned from server.

On the other hand, React is client-side HTML templating library. So it is expected to municate with server via AJAX calls and reading data (in JSON or other format) and inject that data on client using React.

So this will not be easy change. You would need to decouple all your JSP data inject points into services and expose them as JSON data via controllers (taking into account changing of authentication mechanism, input validation, ...). After that refactoring you can start moving your JSP templates into React (most probably JSX). But on that path you realize that you may want to use some UI state management (e.g. Redux). You also discover that you want to structure your ponents into more posable way than most of old JSP templates were. Didn't mention you'll need to also port over some JS that was embedded into these JSPs. Said that, you may end up wiping out all the JSPs altogether and creating UI application from scratch.

You will also discover on that journey stuff like JS testing, UI build pipeline, asset bundling and more goodies of modern UI web development, which will add to overall refactoring.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744970655a277465.html

最新回复(0)