We help IT Professionals succeed at work.

using javabeans to request dynamically created form fields

sonu19 asked
Medium Priority
Last Modified: 2010-03-30
hey guys,

I want to use java beans
I have a form in which I have dynamically created fields. I want to get the values of those fields and put it into a database.

the name of the fields is dynamically created
Watch Question

Pass your request params into your javabean, and you'll have access to all of your submitted data.
make something like this:
Enumerator names = request.getParametersNames();
while (names.hasNext()){
   String value=request.getParameter(names.next().toString);
    // add value to database

Open in new window

send dynamically created fields with types and db column name and then create your sql statement with these info dynamically.

Watch out - the javabean can't see your request. You have to handle it in your DoPost (or DoGet) method, so it would be something like this code. Of course, you haven't been very specific as to how you want to use this stuff, but I'm assuming it's to process the values. If you want to set the values, you'll have to update the response too.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Debug.log(this, "doPost", "new request");
    Map requestNameValuePairs = request.getParameterMap();
    MyJavaBean mjb = new MyJavaBean();
    // and so on
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.