Question

I need to send dynamic complex data (multiple values) from a JSP to a Servlet

I'm working with work history, so the user can provide multiple previous jobs and each job has multiple data associated(company name, date, job title, among others).

As the work history is dynamic I can't use something like request.getParameter("job_title"), I think it can be done with AJAX but I'm not sure how to do it.

This is the jsp file(Dynamic table contains description,company name, job title, start date and end date):

<h2>Work History</h2>
        <fieldset>
            <span class="tab">
                <a href="#" onclick="cloneMe(this); return false;" class="cloneMe" title="Add">+</a>
                <a href="#" onclick="deleteMe(this); return false;" class="deleteMe" title="Delete">x</a>
            </span>
            <table cellspacing="10">
                <tr>
                    <td>
                        <label for="description_hl">
                            Description:
                        </label>
                    </td>
                    <td>
                        <input type="text" id="description_hl" name="description_hl" />
                    </td>
                    <td>
                        <label for="company_h1">
                            Company:
                        </label>
                    </td>
                    <td>
                        <input type="text" id="company_hl" name="company_hl" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="jobtitle_hl">
                            Job title:
                        </label>
                    </td>
                    <td>
                        <input type="text" id="jobtitle_h1" name="jobtitle_h1" />
                    </td>
                </tr>
                                                        <tr>
                    <td>
                        <label for="startDate_hl">
                            Start Date:
                        </label>
                    </td>
                    <td>
                        <input type="date" id="startDate_hl" name="startDate_hl" />
                    </td>
                    <td>
                        <label for="endDate_hl">
                            End Date:
                        </label>
                    </td>
                    <td>
                        <input type="date" id="endDate_hl" name="endDate_hl" />
                    </td>
                </tr> 
            </table>
        </fieldset>
    </br>

Any ideas or direction on how to do send this dynamic data to a servlet?

Was it helpful?

Solution

What I would do is write the table to a DIV via a a script. Then each CloneMe function would be fired with an increment, which would be used to create the input element ID's.

Then I can read them from servlet like request.getParameter("job_title_"+i)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top