Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Trouble retrieving form data in servlet

Options
  • 23-05-2006 9:01pm
    #1
    Registered Users Posts: 1,552 ✭✭✭


    Im trying to write a servlet which when run displays all the data from a database table on the page and allows the person accessing it to modify the table by putting in dates in positions in the table for the dates and then I want to transport the modified table back to mysql.

    Now displaying the data from the mysql database table on the servlet page is not the problem.

    Taking in the modified data is the problem.

    I need to be able to retrieve all the values from the edited table(table after it has been fully edited and submit button has been pressed) including all the modified dates.

    So How would I process the whole table ie. go through all the strings for dates rather than finding just the first date?

    Ive been attempting it using get in the program which displays the data for modification and in my retrieval program Ive only managed to find the first date and don't know how to iterate through all of them please help.


Comments

  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    Use JSF. All the above is a doddle.


  • Registered Users Posts: 1,552 ✭✭✭quinnd6


    Unfortunately I dont have much time.
    Ive been working with servlets up to now and restarting and finding out how to install and setup jsf and how to use it would likely take too much time.
    Any other suggestions?


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    Since you didn't show any code, it's a little difficult. However, you might find it handy to examine what you've been sent back, i.e. to iterate over the data:
    Enumeration e = request.getParameterNames(); // Get all params
    while (e.hasMoreElements()) {
       String nam = (String)e.nextElement();       // Param name
       String data = request.getParameter(nam); // Param value (date)
       System.out.println(nam + "=\"" + data + "\""); 
    }
    
    This'll show what you've got back in the request.


  • Registered Users Posts: 1,552 ✭✭✭quinnd6


    String FuncSpecDate[]= request.getParameterValues("FuncSpecDate");
    String TechDocDate[] = request.getParameterValues("TechDocDate");
    String ManualDate[] = request.getParameterValues("ManualDate");
    String ProjectApproved[] = request.getParameterValues("ProjectApproved");



    for (int i=0; i < FuncSpecDate.length; i++)
    {
    out.println(FuncSpecDate+" "+TechDocDate+" "+ManualDate+" "+ProjectApproved+" ");
    String update = "Update ProjectStatus set FuncSpecSubmitted = \" "+FuncSpecDate+"\"" ;
    statement.execute(update);
    out.println("<BR>");
    }
    statement.close();
    dbcon.close();


    The above code I used to gather the edited date values from the servlet table and then print them out to the screen.
    However I need to transfer the values to the database table.
    As you can see above (hopefully) I just tried it with the funcspecdate but unfortunately that has the effect of changing all the funcspecdates in the mysql table to the last funcspecdate entered rather than updating each date in the mysql table the same way as what was entered on the servlet form.

    So how do I update it properly?

    I was thinking maybe if there was a way of saying

    String update = "Update ProjectStatus set FuncSpecSubmitted = \" "+FuncSpecDate+"\"" where rownum = i;

    that it mite work but there doesn't seem to be any way of saying row no. in mysql?
    or is there?
    can you help?


  • Registered Users Posts: 40 dob99


    Does your table have a primary key? If not, add one, put it into the HTML table as a hidden value and use it to update the DB table.


  • Advertisement
  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    quinnd6 wrote:
    ...that it mite work but there doesn't seem to be any way of saying row no. in mysql?

    Ahh - now I see your problem: you've lost the connection between that particular tuple and the on-screen datum. You need to push the record keys out to the HTML along with the other data, storing the values in hidden fields. The submit then sends the values back, and they'll be available as another parameter on the request.


Advertisement