-2

In a nutshell my question is of the pros and cons of the following potential approaches to migrating an existing java GUI the shows a map being built by a robot in realtime to an HTML5 GUI:

Approach 1 use JQuery, JSON and websockets to connect with the Java back-end and grab the map building information then use the HTML Canvas feature (along with one of the Canvas Libraries) to visualize this information. I believe with this approach I do not need a server side scripting language and that the websockets will allow for the server to send updates without a request.

Approach 2 use JSP. I know very little about JSP but am well versed in java. My thinking is that JSP would allow for direct calls to the existing Java back-end objects requiring less changes to the existing application, however I am not sure if that is how JSP works. Ideally, I would like to call the same functions that are currently used to take the robots sensor data and create a visual map within the HTML5 web app. Further, with this approach I believe I would not need to use JSON or any type of websockets since everything is being done with JSP. However, because this is using a server side scripting language can the server send updated information about the robot and its environment to the HTML client without a request.

Approach 3: I may be completely missing the boat and there is a better alternative

When looking at the two approaches the following elements are needed 1) Whichever approach has to be able to connect to the java back-end 2) All of the information about the robot and the environment are on the Java back-end therefore the approach needs to allow for the HTML client to receive updates without a request 3) Maybe more but not sure

More details: This project involves a robot navigating an unknown environment and building a 2D map based on its sensor data. In the original java GUI version the robot operator would see a blank screen with only the robot visualized as it moved a map of the environment would be built. I need for the HTML5 GUI to do this same functionality.

Doc
  • 179
  • 2
  • 12
  • So I have continue to learn about how the different web technologies work and it appears that what I should do is use a combination of JSP, JSON and JQuery per this stackoverflow link http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax. This will allow me to work with the existing java code and allow for asynchronous communication with the HTML front end. – Doc Jul 31 '14 at 13:03

1 Answers1

0

Its not good to put much logic in JSP, as the info pages for JSP and servlets here on SO will tell you. So for your ajax responses from backend and websockets and returning your JSON you would use servlets rather than JSP. JSP would be reserved for the UI in conjunction with jQuery.

If you can't get websockets working for some reason, you can use ajax polling. That is, have a timer in javascript that sends an ajax request every X seconds and receives a response back from a servlet. Obviously not as efficient, but it works.

Community
  • 1
  • 1
developerwjk
  • 8,619
  • 2
  • 17
  • 33
  • Thanks for the links. I have continue to learn about how the different web technologies work based on this link from stackoverflow http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax. This will allow me to work with the existing java code and allow for asynchronous communication with the HTML front end. However, I still have a question on using websockets is there a benefit to using JSON along with websockets and avoid using server side events all together similar to https://netbeans.org/kb/docs/javaee/maven-websocketapi.html – Doc Jul 31 '14 at 13:31