Answer the question
In order to leave comments, you need to log in
How to get array from Spring when loading JSP page?
You need to write the array to a variable when the page loads. The code below doesn't work:
<c:set var="array" value="${pageContext.request.contextPath}/spring_link/getarray"/>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<c:set var="array" value="${pageContext.request.contextPath}/spring_link/getarray"/>
</body>
</html>
@RequestMapping(value = "/getarray", method = RequestMethod.GET)
public String getArray(ModelMap model) {
Map<String, Class> array = Class.getArray();
model.put("array ", "array");
return "home";
}
Answer the question
In order to leave comments, you need to log in
This:
creates an array variable in the JSP with a string equal to ${pageContext.request.contextPath}/spring_link/getarray
Even more, it is impossible to get data from controllers from a view returned by a non-Spring WebMVC controller (more precisely, it is possible, but these are crutches). In standard WebMVC, the controller decides which view to give back and what data to pass to the view via models. This is not JSF / CDI for you, although if you really want to, you can cross JSF / CDI with Spring, but these are also perversions.
There is only one correct option - the controller returns the desired view and passes the necessary data to it.
PS: why solve problems in ways that contradict established concepts?
Handles data from Spring like this:
<c:forEach items="${arrays}" var="array"> //принимаем массив
${array.String}
${array.Class.(поля)}
</c:forEach>
@RequestMapping(value = "/getarray", method = RequestMethod.GET)
public String getArray(ModelMap model) {
Map<String, Class> array = Class.getArray();
model.addAttribute("arrays ", array); // передаем в jsp массив
return "home";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question