简体   繁体   中英

Transfer ResultSet from Java to JSP using Ajax

I have a ResultSet in my Java class. How can I transfer this ResultSet to a jsp without using scriptlets?

I am assuming you are using a spring controller method and returning the JSP for a request.

You can set any object into the ModelView and return the ModelView object and spring will set all these objects into the response.

@Controller
public ClassName {
  ....

@RequestMapping(value = "/ex/foos", method = RequestMethod.GET)
@ResponseBody
public ModelAndView postFoos(HttpServletRequest request,
        HttpServletResponse response) {
    ModelAndView model = new ModelAndView("myjsppage");
    model.addObject("msg", "hello world");
    return model;
}

Meanwhile in the JSP, you can use this.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
     <h1>Spring MVC Hello World Example</h1>
     <h2>${msg}</h2>
</body>
</html>

Note that you can set any objects into the modelView. I just gave this String as an example. You can use JSTL and EL in the JSP to iterate/view value of objects.

These links might help

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-coc-modelmap

http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/

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