How to servlet println(); tag <c:forEach>

余生长醉 提交于 2020-01-07 09:45:36

问题


anyone have idea to slove my problem?

I need to use servlet to println the jsp like this.

<select name="users_province" id="users_province" class="form-control">
<option value="0" selected="selected">Province</option>
<c:forEach items="${provincesList}" var="lists" >
<option value="${lists.provinceCode}">${lists.provinceNameTh}</option>
</c:forEach>
</select>

This is my servlet code.

pw.println("<select name=\"users_province\" id=\"users_province\" class=\"form-control\">");
pw.println("<option value=\"0\" selected=\"selected\">Province</option>");
pw.println("<c:forEach items=\"${provincesList}\" var=\"lists\" >");
pw.println("<option value=\"${lists.provinceCode}\">${lists.provinceNameTh}</option>");
pw.println("</c:forEach>");
pw.println("</select>");

But my code print like this.

<select name="users_province" id="users_province" class="form-control">
<option value="0" selected="selected">Province</option>
<option value="${lists.provinceCode}">${lists.provinceNameTh}</option>
</select>

My selectbox


回答1:


For this case i solve it by this code.

pw.println("<select name=\"users_province\" id=\"users_province\" class=\"form-control\">");
pw.println("<option value=\"0\" selected=\"selected\">Province</option>");
for(int i=0;i<provincesList.size();i++){
pw.println("<option value=\"" + provincesList.get(i).getprovinceCode() + "\">" + provincesList.get(i).getprovinceNameTh() + "</option>");
}
pw.println("</select>");


来源:https://stackoverflow.com/questions/57670934/how-to-servlet-println-tag-cforeach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!