• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Cannot fetch data from arraylist

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to fetch names of friends having same hobby and My problem is I cannot set object of listbox in arraylist and cannot retrive names from list Please help me.

This is my HTML page
<!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">
<title>Parameter in JSP </title>
</head>
<body>
<form method="post" action="TestJSP5.jsp">
<select name="hobby" size="1">
<option>Horse Riding</option>
<option>Boating</option>
<option>Extreme Knitting</option>
<option>Speed Dating</option>
</select>
<select name="names" size="5" multiple="multiple" >
<option value ="ravi"> ravi</option>
<option value="Akash">Akash</option>
<option value="vab">Vab</option>
<option value="gustav">gustav</option>
</select>
<br>
<br>
<center>
<Input type="Submit" value="Enter">
</center>
</form> "
Parameter in JSP through HTML
</body>
</html>

This is my JSP Page

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

<!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">
<title>Parameter</title>
</head>
<body>
The friends who share the hobby
<%=request.getParameter("hobby")%>
are: <br>
<%List al=new ArrayList(); %>
<%al.add(0); %>
<%al.add(1); %>
<%al.add(2); %>
<%al.add(3); %>

<%request.setAttribute("names",al); %>

<% al=(ArrayList)request.getAttribute("names");%>
<%if (al!=null && al.size()>0){ %>
<%Iterator it=al.iterator(); %>
<%while(it.hasNext()){ %>
<%=it.next() %>
<%}} %>
</body>
</html>

 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few points:
  • Java and scriptlets in a JSP is a bad bad practice. You should strive to stop doing that.
  • You should submit forms to servlets, not to JSPs. That will also make fetching the data easier.
  • You haven't really told us what's happening, just that "I can't do it". That doesn't help us help you.


  • So what's really the problem? What have you debugged so far?
     
    Gaurav x Jain
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry for the inconvience. In this jsp page There are 1 combobox and 1 listboxe combobox contains Hobbies and listbox contains name of friends. I just want to select a hobby then select multiple names from friend list and display it to web page output must like

    The friends who share the hobby Boating are:
    ravi
    vab
     
    Bear Bibeault
    Sheriff
    Posts: 67595
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Then why bother with a list at all? If you are going to continue to submit to a JSP rathe than a servlet (bad practice) then the submitted parameters are available via the param built-in scoped variable which you can access with the EL.
     
    Gaurav x Jain
    Ranch Hand
    Posts: 39
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you. Now it's working
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic