programmatically creating input form elements in jsp -


I have a unique requirement where input text elements on my JSP are displayed based on the data from a table in the database. It is an idea that is displayed programmatically to display the input element on JSP rather than hard coding. Since I'm working with hundred weird input elements, I thought that the creation of the Jasonan object would be the most viable option, but it does not actually help when doing server-side legalization. So I finally decided to use Spring MVC and strictly coding every element in JSP which is not the best way to do this in this situation. Is there a better and elegant way to dynamically build a form when we are not sure what the input elements are going to be (in this case the list is coming from the database)?
I appreciate your feedback. >

Are you getting a simple list of strings from your database?
Can you use JSTL? If not, you can use a script. But, many people do not like to use one anyway, here too there is a JSP that shows both methods.

  & lt;% @ Page Import = "Java.Pile. *"% "% & Gt; & Lt;% @ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%> Create list for list of & lt;% test / lt; String & gt; List = New Arrestist & lt; String & gt; (); List.add ("blue"); List.add ("green"); List.add ("red"); List.add ("yellow"); PageContext.setAttribute ("list", list); & Gt%; & Lt; Html & gt; & Lt; Body & gt; & Lt; Form & gt; & Lt; C: forEach item = "$ {list}" var = "current" & gt; $ {Current} & lt; Input name = "$ {current}" type = "text" /> & Lt; / C: foreach & gt; & Lt; Br / & gt; & Lt;% (string item: list) {out.print (item + "& lt; input name = \" "+ + object +" \ "type = \" text \ "/ & gt;"); }% & Gt; & Lt; Input type = "submit" / & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

Comments