Solved

hidden fields in jsp

Posted on 2011-02-16
3
1,159 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Performance issue while iterating with streams 5 39
triangle challenge 4 79
sumDigits  challenge 7 61
java set up 1 47
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now