aspose file tools
The moose likes Servlets and the fly likes Multiple select value retrieval in JSP page????? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Multiple select value retrieval in JSP page?????" Watch "Multiple select value retrieval in JSP page?????" New topic
Author

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

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
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

Joined: Jan 29, 2001
Posts: 7
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

Joined: Dec 20, 2000
Posts: 111
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

Joined: Dec 30, 2000
Posts: 185
Thanks a lot, it's really very helpful.
Lusha
 
 
subject: Multiple select value retrieval in JSP page?????
 
Threads others viewed
Any Suggestion about a small project?
session management problem with iframes
calling a java Script file into the Jsp
urgent !!!!how to access contents of list in jsp
Please solve the problem.
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture