Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple select value retrieval in JSP page?????

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I select many options in a drop down menu(html tag "select" with "multiple")& submits the data in a Database table field.Seperating all the selected values with Commas(",").
now the problem is:
I want to let the user see what he had selected previous time he visited the page.i retreive the values entered by the user in a String & seperates them using String Tokenizer.Now i don't know how to proceed further.
where do i insert the scripplet so as to prevent the duplication of the selected values.
here is the HTML code:

<TD><SELECT NAME="fskills" SIZE="3" multiple >
<option selected value="VB">Visual Basic
<option value="JAVA">JAVA
<option value="ASP">ASP
<option value="SERVLETS">SERVLETS
<option value="EJB">EJB
<option value="MS-SQL">MS-SQL
<option value="ORACLE">ORACLE
<option value="MS-ACCESS">MS-ACCESS
</SELECT> </TD>
Hope i am clear in explaining my problem
Thanks in advance
Shalu
 
Sandra Sharpe
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using JDK1.2 you can try this.....

<%@ page import="java.util.List, java.util.Arrays" %>
<html>
<body>
<%
String[] values = request.getParameterValues("fskills");
for ( int i =0; i < values.length; i ++ ) {
out.println("<li>Value : " + i + " is : " + values[i]);
}//for
List userChoices = java.util.Arrays.asList( values );
%>
<form method="post" action="multi.jsp">
<SELECT NAME="fskills" SIZE="3" multiple >
<option <%= userChoices.contains("VB") ? "selected" : "" %> value="VB">Visual Basic
<option <%= userChoices.contains("JAVA") ? "selected" : "" %> value="JAVA">JAVA
<option <%= userChoices.contains("ASP") ? "selected" : "" %> value="ASP">ASP
<option <%= userChoices.contains("SERVLETS") ? "selected" : "" %> value="SERVLETS">SERVLETS
<option <%= userChoices.contains("EJB") ? "selected" : "" %> value="EJB">EJB
<option <%= userChoices.contains("MS-SQL") ? "selected" : "" %> value="MS-SQL">MS-SQL
<option <%= userChoices.contains("ORACLE") ? "selected" : "" %> value="ORACLE">ORACLE
<option <%= userChoices.contains("MS-ACCESS") ? "selected" : "" %> value="MS-ACCESS">MS-ACCESS
</SELECT>
<input type="submit" value="submit">
</form>
</body>
</html>

There are probably better ways keep the JSP and Java separated but I hope this answers your question.
 
Laojar Chuger
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just initiate with user's selection. As of the dynamic nature of the problem, you may need to use Javascript for this purpose. Check how to do form initiation in the Javascript object section.
 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, it's really very helpful.
Lusha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic