Adi
Adi

Reputation: 1455

How to send label parameter from JSP to servlet?

I have a jQuery dialogue box which contains values as checkboxes. On selecting the checkboxes I am storing the selected values into label. Next I have to send these values from label as parameter through form to servlet but I don't know how to complete it.

Here is my code:

<form action="CallTimer" method="GET">
    <label class="button2">Set Date: </label>
    <input type="text" name="date" id="date" size="4">

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="Submit" name="Submit" value="Submit" id="Submit">

    <br/> 
    <a href="javascript:void(0)" id="departmentlink" class="button2">Select Reporting Level</a>
    &nbsp;&nbsp;
    <label class="button2" style="display:none" id="depart">&nbsp;Department</label> 
</form>

I am retrieving these parameters in my Servlet as:

String reportname=request.getParameter("depart");
System.out.println(reportname);

But it is returning null values. Please help me.

Thanks in advance.

Upvotes: 1

Views: 5491

Answers (2)

Vitalii Pro
Vitalii Pro

Reputation: 313

You have to use hidden input field:

<input type="hidden" name="depart" />

Upvotes: 3

jny
jny

Reputation: 8057

You need to understand what gets passed on form submission and what is not. In a nutshell, only values of the input fields get sent to the server. You have several ways to solve your problem:

  1. Write value to a hidden input field
  2. Modify the query string (what gets sent after ? in your GET request) during form submission (using java script):

    ?...&depart=xxx

Upvotes: 1

Related Questions