I am trying to generate the <htmlption> tags in my action class and store it in action form to display on the screen. I am using html:select tag and my code looks like this.
When I set the value to the form variable fieldValue in the struts Action class to something like
I am not able to see the value in the select dropdown in the screen.
The htmlption tag, or for that matter, any Struts tag will work only if you place it directly in the JSP, not if you generate it through a scriptlet. To understand why it won't work to generate it in a scriptlet, let's review the JSP life cycle:
The JSP interpreter reads the JSP file, including any custom tags such as Struts tags and converts everything to Java source code
It then compiles it into a class file
It executes the code, rendering a response in plain HTML and sending it back to the browser.
It is only at this point that the scriptlet code you inserted gets executed. It is now too late in the cycle to insert any custom tags, since they've already been interpreted by this point.