0
我是JSTL和Spring Framework的新手。我正在嘗試使用JSTL標籤在彈出窗體中填充下拉列表。這些值來自Enum class
。但由於某種原因,我收到一個空白列表。沒有錯誤消息。使用JSTL從枚舉類獲取下拉列表到JSP
枚舉類:
package edu.bnu.fyp.stp.constants;
public enum TutorType {
Home_Tutor ("Home Tutor"), Online_Tutor ("Online Tutor");
private String tutorType;
private TutorType(String s){
tutorType = s;
}
public String getTutorType() {
return tutorType;
}
public void setTutorType(String tutorType) {
this.tutorType = tutorType;
}
}
控制器類:
@RequestMapping(value = "/studentdashboard/requirement")
public String showPostRequirement(Model model){
List <TutorType> tutorTypes = tutorTypes = new ArrayList<TutorType (Arrays.asList(TutorType.values()));
model.addAttribute("TutorType", TutorType.values());
return "Requirement";
}
JSP
<select name="${status.expression}" name="TutorType" id="TutorType">
<option value=""></option>
<items="${TutorType}" var="option">
<option value="${option}">
<co:out value="${option.tutorType}"></co:out>
</option>
</>
</select>
請讓我知道我這樣做不對?謝謝
爲什麼不使用Spring MVC自己的'
如果你做了一個''而不是那個沒有名字的標籤,它會有所幫助。如果你真的將'TutorType'添加到'model',它也會有所幫助。 –
Andreas
這是一個錯字,我確實在模型中添加了TutorType。只是更新了說明。 –