简体   繁体   中英

Is there a way to retrieve data from redis in my jsp pages?

I am creating a spring boot server, and I would like the initial page (index.jsp) to be a datatable with information coming from the redis database. Anyone know how to do this with javascript or inside jsp pages?

First of all JSPs are outdated technology so I recommend you to go for thymeleaf which is a perfect choice with spring boot instead of JSP.

JAVA approach :

Just create a mapping with / base url and fetch Redis data using normal approach and use it in UI.

GetMapping("/")
public String index(){
  //Fetch Redis data here add into model attributes
 return "index";
}

JavaScript/inside JSP approach :

You can create a mapping method with some url like above and make an AJAX call on page load from the JSP page and get the JSON format data and use it.

Don't forget to put @ResponseBody annotation on top of the method which will return the data(JSON) instead of the page.

Refer call ajax to spring controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM