Solved

hidden fields in jsp

Posted on 2011-02-16
3
1,171 Views
Last Modified: 2012-05-11
<form method="post">

<select name ="getselected" id="getselected">
<option>fox</option>
<option>fox2</option>
<option>fox3</option>
</selected>

<input type="hidden" name="hidden" value="<%=getselected%>">

</form>




on server side

String selectedvalue = (String)request.getParameter("hidden");



when i use hidden field in jsp it showed me an error

Multiple annotations found at this line:
      - Tag (input) should be an empty-
       element tag.
      - getselected cannot be resolved to a
       variable
0
Comment
Question by:shragi
  • 2
3 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34908700
while loading the page <%=getselected%> is null so that only its give error more over you cant get that value directly .

try this

String selectedvalue = (String)request.getParameter("getselected");
0
 
LVL 27

Accepted Solution

by:
rrz earned 250 total points
ID: 34909433
I have been reading your other questions. This a javascript question.  
If your hidden field in your form is
<input type="hidden" name="fileLocation" value="not yet">
and you have
 <select name="selectedFile" >
...
</select>
and you have
<input class="button" value="Submit" type="button" onclick="performAction2()" />
then your script will be  
<script language="JavaScript" type="text/javascript">
   function performAction2() {
       document.forms[0].fileLocation.value = 
              document.forms[0].selectedFile.options[document.forms[0].selectedFile.selectedIndex].value;
       document.forms[0].submit();
   }
</script>

Open in new window

0
 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 250 total points
ID: 34913592
if u want to set the values dynamically then u can use JSTL tag

Before loading the page jsut set the hiddenValue as blank

request.setAttribute("hiddenValue","");
In jsp
<input type="hidden" name="hiddenV" value="${hiddenValue}">
while changing the dropdown call some java script
set the value in java script function
document.forms[0].hiddenV.value=document.forms[0].getselected.value
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
Spring Framework HTTPSession management 1 36
Arrays.asList  VS  ArrayList 4 60
login form jsp example 2 25
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question