我是java web編程,servlet和JSTL中的新成員。 我想要做的是如何從枚舉中獲取值,並使用JSTL在我的jsp頁面中進行驗證;在JSP中使用枚舉值進行驗證
這裏是我的枚舉
package RenewalVo.common;
public enum RenewalConstant {
//MODUL_TASK
MT_REGISTRATION(46),
MT_DISTRIBUTION(47),
MT_ACTION_PLAN(70);
private int constantId;
private RenewalConstant(int s) {
constantId = s;
}
public int getConstantCode() {
return constantId;
}
}
這裏是我的jsp頁面讓代碼說validationpage.jsp
<c:choose>
<c:when test="${drafId!=0 }">
<c:choose>
<c:when test="${modulTaskId== //here is which i would like to get the enum value for validation}">
// do something here
</c:when>
<c:when test="${modulTaskId== //here is which i would like to get the enum value for validation}">
// do something here
</c:when>
<c:otherwise>
//do something here
</c:otherwise>
</c:choose>
</c:when>
</c:choose>
爲draftId和modulTaskId我從servlet的檢索,並通過RequestDispatcher的轉發。
這裏是我的servlet代碼
request.setAttribute("modulTaskId",modulTaskId);
request.setAttribute("drafId",drafId);
RequestDispatcher view = request.getRequestDispatcher(/validationpage.jsp);
view.forward(request, response);
希望sumbody可以提供幫助。
預先感謝您。