Click here to Skip to main content
15,891,864 members

passing list from jsp to servlet

Member 3369145 asked:

Open original thread
i want to pass a list from the jsp page to a servlets, i need details.

i want to pass the fruits[i] list in my code to servlets.

following is my jsp code:

====================================

XML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function checkBoxValidation()
{
for(var i=0; i < document.form1.fruit.length; i++)
{
if(!document.form1.fruit[i].checked)
{
alert("Please Select objects ");
return false;
}
else
{
alert("Click OK to display your selected objects list");
return true;
}
}
}
</script>
<title>JSP Multiple Checkbox</title>
</head>
<body>
<form name="form1" onsubmit="checkBoxValidation()">
<h3>Select Object to Compose Service</h3>
<p><input type="checkbox" name="fruit" value="Temperature"/>temperature</p>
<p><input type="checkbox" name="fruit" value="Humidity"/>humidity</p>
<p><input type="checkbox" name="fruit" value="Smoke"/>Smoke</p>
<p><input type="checkbox" name="fruit" value="floor"/>floor</p>
<p><input type="checkbox" name="fruit" value="date"/>date</p>
<p><input type="checkbox" name="fruit" value="time"/>time</p>
<p><input type="submit" value="submit"/>

</form>
<%
String fruits[]= request.getParameterValues("fruit");
request.setAttribute("listName",fruits);
if(fruits != null)
{
%>
<h4> You have selected following Objects </h4>
<ul>
<%
for(int i=0; i<fruits.length; i++)
{
%>
<li><%=fruits[i]%></li>
<%
}
%>
</ul>
<%
}
%>
</body>
</html>
Tags: Javascript, Servlet

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900