0

I am using spring,i need to create XML file when i click on a button. I need to pass the value of a hidden element as parameter in href.

How can i achieve this , any help would be appreciable

snippet of my code am attaching here

   <div class="portlet-body no-more-tables" id="testf"> 
    <input type="hidden" id="testID" value="dd"><br/> <div style="margin-left:100px">
      <a style="" href="incident/test/testHref.do?testID=<%=testID%>" id="createReport">     Create Report </a> 
    </div>
     </div>
Santhosh
  • 8,181
  • 4
  • 29
  • 56
user3132347
  • 363
  • 1
  • 7
  • 27

1 Answers1

0

You need to add the html attribute name to the hidden parameter ,so that you will get the value in the request

<input type="hidden" name="testID" id="testID" value="dd"><br/> <div style="margin-left:100px">

And testID should be Java variable to embed inside the URL as you have used the scriptlets. so you cant pass it in the get request. Instead use POST method to get the variable available in the request.

is the trivial way to hardcode the elements in the url.

You can also assign the values to the variable testID using scriptlets,

<% String testID="dd" ; %> 

so that it will available when you try to pass like ,

<a style="" href="incident/test/testHref.do?testID=dd" id="createReport">Create Report </a>

As scriptlets are not advised over the decades , can be replaced with jstl ,

<c:set var="testID" value="dd" />

see How to avoid Java code in JSP files?

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • @ san krish , thank u so much for your kind reply,but my hidden variable is not static,that variable value will change dynamically,so cannot pass as this href="incident/test/testHref.do?testID=dd", here "dd" i have put as an example.i need to pass current value of hidden vairable – user3132347 Oct 29 '14 at 07:30
  • If you hidden variable in dyanamic (available in the request) . you can do `` . so that you will have the value in the varible `testID` – Santhosh Oct 29 '14 at 07:32
  • why am using hidden input element instead of variable, that value updates as per the click of another button ,there is no server request,its only jquery function,so how can I dynamically update jstl variable,i need the hidden input element current value when call href each time – user3132347 Oct 29 '14 at 07:36