小编Ste*_*anu的帖子

使用 Spring 在 JSP 上显示值列表

我想在我的 jsp 视图中显示我的值列表,但我不能这样做。

下面是我的控制器类,它只是将 List 添加到ModelAndView地图,然后重定向到我的index.jsp页面。

员工控制器

@Controller
public class EmployeeController {

@RequestMapping(value={"/employee"}, method = RequestMethod.GET)
public String listEmployee(){    
    System.out.println("Kontroler EmployeeController");
    LinkedList<String> list = getList();
    ModelAndView map = new ModelAndView("index");
    map.addObject("lists", list);

    return map.getViewName();
}

private LinkedList<String> getList(){
    LinkedList<String> list = new LinkedList<>();

    list.add("Item 1");
    list.add("Item 2");
    list.add("Item 3");

    return list;
}

}
Run Code Online (Sandbox Code Playgroud)

索引.jsp

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Welcome to Spring Web MVC project</title>
</head>

<body>
    <h1>Index page</h1>
    <h1>${msg}</h1>
    <a href="/MavenHello/employee">Zam?stnanci</a>
</body>
    <c:if test="${not …
Run Code Online (Sandbox Code Playgroud)

java spring jsp spring-mvc modelandview

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

jsp ×1

modelandview ×1

spring ×1

spring-mvc ×1