0

Currently, I have connected to my database in MYSQL using JSP code. However, my next step would be to use something like Plotly.js to create a graph. However, I can't seem to be able to transfer values that I retrieve through JSP into javascript where Plotly is to create the graph. I also want my graph to be dynamic in the sense that I can run my program and it'll update it with the changes to the database. I hear that transferring values from JSP to javascript isn't recommended so I was wondering what is an efficient strategy to solve my problem?

Steven
  • 35
  • 6
  • i'm assuming you are using scriptlets in your jsp? Because that's where the problem will be. You need to create a servlet and call on that servlet to get the values from the database which you can then pass to Plotly – Jonathan Laliberte Jun 26 '18 at 19:40
  • Yeah, I am using scriptlets in my jsp. When I create a servlet and call on it, how would I pass it into plotly? Sorry, I am new to jsp and this topic in general. – Steven Jun 26 '18 at 20:32
  • you call on your servlet in javascript with AJAX. Then you pass the values to plotly, which is also javascript. – Jonathan Laliberte Jun 26 '18 at 20:33
  • Hmm, alright. I need to familiarize myself with AJAX and XML first. Do you have another possible solution without a new language? – Steven Jun 26 '18 at 20:42
  • AJAX isn't a new language, it's just a way of using javascript so that you can make asynchronous requests to your server (so you can get information from your server without refreshing the page). Plotly uses javascript and you need to feed plotly javascript variables... There is no other way to do it. – Jonathan Laliberte Jun 26 '18 at 20:54
  • could you possibly show me an example of ajax code passing into a variable I can use in javascript with an explanation? I can't seem to grasp the concept through searching – Steven Jun 27 '18 at 16:01
  • are you using servlets? – Jonathan Laliberte Jun 27 '18 at 17:22
  • Yes I am using a servlet – Steven Jun 27 '18 at 19:02
  • then check out this resource, the answer to this question will give you everything you need to know when working with AJAX. Try the simple examples first so you understand what is going on https://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax – Jonathan Laliberte Jun 27 '18 at 19:07

0 Answers0