从Spring-mvc获取数据到jstl
Get data from Spring-mvc to jstl
我已经 spring mvc 示例设置和一个名为 return 的学生编辑到 student.jsp:
return new ModelAndView("student","c", student);
如果student.jsp不包含jstl,那么它工作正常:
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring MVC Form Handling</title>
</head>
<h2>Student Information</h2>
<form:form method="POST" action="/HelloWebForm/student" id="FORM_ID_01">
<table border="1" id="myTable">
<tr>
<td><form:label path="name">Name</form:label></td>
</tr>
<tr>
<td><form:textarea path="name" placeholder="default Value" /></td>
</tr>
</table>
</form:form>
</body>
</html>
但如果我尝试在 student.jsp 中使用 jstl,则它不起作用:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Spring MVC Form Handling</title>
</head>
<body>
<c:out value="${student.name}" />
</body>
</html>
它不给出任何错误信息,它只是不写任何东西。我在这里错过了什么?提前致谢。
在您的操作中,您可以这样做:
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("student", student);
modelAndView.setViewName("path/to/your/view");
return modelAndView;
并且您的查看代码是正确的。我认为这会起作用。
我已经 spring mvc 示例设置和一个名为 return 的学生编辑到 student.jsp:
return new ModelAndView("student","c", student);
如果student.jsp不包含jstl,那么它工作正常:
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring MVC Form Handling</title>
</head>
<h2>Student Information</h2>
<form:form method="POST" action="/HelloWebForm/student" id="FORM_ID_01">
<table border="1" id="myTable">
<tr>
<td><form:label path="name">Name</form:label></td>
</tr>
<tr>
<td><form:textarea path="name" placeholder="default Value" /></td>
</tr>
</table>
</form:form>
</body>
</html>
但如果我尝试在 student.jsp 中使用 jstl,则它不起作用:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Spring MVC Form Handling</title>
</head>
<body>
<c:out value="${student.name}" />
</body>
</html>
它不给出任何错误信息,它只是不写任何东西。我在这里错过了什么?提前致谢。
在您的操作中,您可以这样做:
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("student", student);
modelAndView.setViewName("path/to/your/view");
return modelAndView;
并且您的查看代码是正确的。我认为这会起作用。