jsp - How to set values in drop down using JSTL from db -
i have populated arraylist() info in drop downwards using jstl. when tried set value bean getter method 'designate' (a submitted db value). exception occurs. suggestions please. in advance...!!
servlet attribute
request.setattribute("result2", ldesignation);
jstl tag
<jsp:usebean id="userprofile" class= "com.package.dao.userprofile" scope="request"/> <jsp:setproperty name="userprofile" property="*" /> <strong>designation</strong>: <select id="designate" name="designate"> <option value="desigtype">select designation</option> <c:foreach var="desig" items="${result2}"> <option value="${desig.key}" ${desig.key == ${userprofile.designate ? 'selected="selected"' : ''}>${desig.value}</option> </c:foreach> </select> <br>
exception
javax.el.propertynotfoundexception: property 'key' not found on type java.lang.string @ javax.el.beanelresolver$beanproperties.get(beanelresolver.java:266) @ javax.el.beanelresolver$beanproperties.access$300(beanelresolver.java:243) @ javax.el.beanelresolver.property(beanelresolver.java:353) @ javax.el.beanelresolver.getvalue(beanelresolver.java:97) @ org.apache.jasper.el.jasperelresolver.getvalue(jasperelresolver.java:104) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:183) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) atorg.apache.jasper.runtime.pagecontextimpl.proprietaryevaluate(pagecontextimpl.java:967) @ org.apache.jsp.home_jsp._jspx_meth_c_005fforeach_005f0(home_jsp.java:510) @ org.apache.jsp.home_jsp._jspservice(home_jsp.java:279) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:748) atorg.apache.jasper.jasperexception: exception occurred processing jsp page /home.jsp @ line 158 155: <strong>designation</strong>: <select id="designate" name="designate"> 156: <option value="desigtype">select designation</option> 157: <c:foreach var="desig" items="${result2}"> 158: <option value="${desig.key}" ${desig.key == ${userprofile.designate ? 'selected="selected"' : ''}>${desig.value}</option> 159: </c:foreach> 160: 161: </select> <br>
found reply setting bean value variable , checking if status in foreach loop.
<strong>designation</strong>: <select id="designate" name="designate"> <option value="desigtype">select designation</option> <option value="${selecteddesig}" selected>${selecteddesig}</option> <c:foreach var="designate" items="${result2}"> <c:if test="${designate != selecteddesig}"> <option value="${designate}">${designate}</option> </c:if> </c:foreach> </select> <br>
jsp servlets jstl
No comments:
Post a Comment