从spring控制器访问JSP的JSTL值
下面是我在jsp文件中的主体。在我的spring应用程序中,我想将所有div值转发给我的控制器。我试图访问一个div(名为='atcId')的数据,但无法访问从spring控制器访问JSP的JSTL值,spring,jsp,jakarta-ee,spring-mvc,servlets,Spring,Jsp,Jakarta Ee,Spring Mvc,Servlets,下面是我在jsp文件中的主体。在我的spring应用程序中,我想将所有div值转发给我的控制器。我试图访问一个div(名为='atcId')的数据,但无法访问 <body> <br> <div class="head" style="text-align:center; width:80px; float:left"> Route </div> <div class="head" style=
<body>
<br>
<div class="head" style="text-align:center; width:80px; float:left">
Route
</div>
<div class="head" style="text-align:center; width:300px; float:left">
Date
</div>
<div class="head" style="text-align:center; width:140px; float:left">
Time
</div>
<div class="head" style="text-align:right; width:100px; float:left">
Capacity
</div>
<div class="head" style="text-align:center; width:100px; float:left">
</div>
<br>
<div class="head" id="empty" style="text-align:center; width:80px; float:left">
</div>
<div class="head" style="text-align:center; width:150px; float:left">
From
</div>
<div class="head" style="text-align:center; width:150px; float:left">
To
</div>
<div class="head" style="text-align:center; width:70px; float:left">
From
</div>
<div class="head" style="text-align:center; width:70px; float:left">
To
</div>
<div class="head" style="text-align:right; width:100px; float:left">
</div>
<div class="head" style="text-align:center; width:100px; float:left">
</div>
<br>
<br>
<form action='atc/edit.htm' method="post">
<c:forEach items="${atcMap}" var="atc" varStatus="status">
<div style='float:left'>
<div class="data" name="atcId" style="text-align:center; width:80px; float:left">
<c:out value="${atc.key.elements.name}"/>
</div>
<div class="data" style="text-align:center; width:150px; float:left">
<c:out value="${atc.key.id.fromDate}"/>
</div>
<div class="data" style="text-align:center; width:150px; float:left">
<c:out value="${atc.key.toDate}"/>
</div>
<div style='float:left'>
<c:forEach items="${atc.value}" var="atcSchedule" varStatus="status">
<div class="data" id="atcId" style="text-align:center; width:70px; float:left">
<c:out value="${atcSchedule.id.fromBlock}"/>
</div>
<div class="data" style="text-align:center; width:70px; float:left">
<c:out value="${atcSchedule.toBlock}"/>
</div>
<div class="data" style="text-align:right; width:100px; float:left">
<c:out value="${atcSchedule.capacity}"/>
</div>
<br>
<br>
</c:forEach>
</div>
<input type="image" width="25" height="25" name="action" id="image" value="modify" src="<c:url value="/resources/images/modify.png"/>" alt="Modify">
<input type="image" width="25" height="25" name="action" id="image" value="delete" src="<c:url value="/resources/images/delete.png"/>" alt="Delete">
</div>
<div style='clear:both'>
</div>
<hr id="rowbreak" style="text-align: center">
</c:forEach>
</form>
</body>
您需要将所有JSTL值设置为具有专有名称/ID的输入标记(隐藏类型)。然后,您可以通过使用访问控制器中的隐藏输入
request.getParameterValues(“hiddenInputId”)代码>
@RequestMapping(value="/atc/edit", method=RequestMethod.POST)
public ModelAndView editATC(@ModelAttribute("message") String message, HttpServletRequest request, HttpServletResponse response) throws ServletException
{
System.out.println(request.getParameter("action"));
System.out.println(request.getParameter("atcId"));
ModelAndView mav = new ModelAndView();
mav.setViewName("view_ATCMaster");
mav.addObject("message", message);
return mav;
}