我有一个旧的 MVC 应用程序。
它有一个控制器,其方法如下:
@RequestMapping(method=RequestMethod.GET)
public ModelAndView handleGet(@RequestParam(value="userId") String userId){
ModelMap model = new ModelMap();
List<Long> relatedIds = getListOfIds(userId)
RelatedIdFormHolder();
formHolder.setRelatedIds(relatedIds);
model.put("relatedIdFormHolder", formHolder);
return new ModelAndView("relatedIds.jsp", model);
}
我有一个 .jsp,其形式如下:
<form:form method="post" commandName="relatedIdFormHolder" id="relatedIdFormHolder" onsubmit="submit_form()">
<form:select path="selectedId">
<form:options items="relatedIds"></form:options>
</form:select>
</form:form>
我有一个像这样的 POJO:
public class RelatedIdFormHolder {
public List<Long> getRelatedIds() {
return relatedIds;
}
public void setRelatedIds(List<Long> relatedIds) {
this.relatedIds = relatedIds;
}
public String getSelectedId() {
return selectedId;
}
public void setSelectedId(String selectedId) {
this.selectedId = selectedId;
}
List<Long> relatedIds;
String selectedId;
}
我访问了正确的 URL,并映射到正确的控制器,然后映射到正确的 .jsp,但是 JSP 在呈现时抛出错误:
ERROR: error500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items
我尝试从视图中来回传递relatedIds 和 selectedID 作为字符串和Longs,但遇到同样的问题。
什么给了,这应该是直截了当的,我错过了什么?