I want to extract all the values for a specific drop down list box in a web form.
In the source code of this web form, the relevant code for this particular drop down, is given below–
<div align="left"><select name="CATEGORY_ID">
<option label="[Top]" value="0" selected="selected">[Top]</option>
<option label="|___Arts & Humanities" value="1">|___Arts & Humanities</option>
<option label="| |___Art History" value="2">| |___Art History</option>
----many more values----
<option label="| |___Work" value="453">| nbsp;|___Work</option>
</select>
</div>
I want to extract both the actual values (ie option … value=”” ) as well as the value shown on screen (ie option label=”” )…Can this be done in JSP/Java? And ideally done using only classes supported by Google App Engine? (Even if you can suggest a way to do this but are not sure if that way is supported by Google App Engine for Java, even then kindly suggest your method…)
Easiest is to use a HTML parser for this. I don’t think that GAE ships with any one. But you should be able to drop one in your
/WEB-INF/lib. I’d suggest to grab Jsoup for this job. You should then able to obtain all options of a<select name="CATEGORY_ID">of the external website as follows in a servlet:And then in JSP redisplay it as follows:
The
labelattribute is by the way unnecessary as it’s a silly MSIE-proprietary attribute. It’s the body of the<option>element which is to be shown as visible label.