简体   繁体   中英

Custom tag Java Jsp - How to set attribute base on a dropdown list selection

I have a Java Jsp custom tag with attributes. These attributes are selectable from a drop down list. So how can I set attribute to my custom tag base on the selection from the dropdown list?

For example:

<select>
   <option>A</option>
   <option>B</option>
   <option>C</option>
</select>
<prf:customTag atribute1="[***]"/>

So [ * ] is set to "A" if I selected A from the dropdown list, "B" if I selected B, and "C" so on.

Your select must be within 'form' tags as follows:

<form method="POST" action="myPage.jsp">
  <select name="optionSelected">
     <option>A</option>
     <option>B</option>
     <option>C</option>
  </select>
  <input type="submit">                     

The current page is called myPage.jsp and when the form is submitted the value selected from the drop-down will be passed to the jsp page in the request parameter and therefore can be retrived and used as the input to the cutom tag.

<prf:customTag atribute1="${ param.optionSelected }"/>

The option selected from the drop-down list will be retrived from the parameters posted to the myPage.jsp and inserted in the custom tag using Exxpression Language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM