• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

String Arraylist from Java to Javascript

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ho do I access an Arraylist from a servlet in Javascript on a JSP

What is the best possible way.Any suggestions please
 
Sheriff
Posts: 67762
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
You obviously cannot pass the data directly. You'll need to create the JavaScript markup that recreates the data.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe DWR is the thing you want
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here's sample code for DOB...njoy

servlet :

public class ArrayListDemo extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

ArrayList monthList = new ArrayList();

monthList.add("Jan");
monthList.add("Feb");
monthList.add("Mar");
monthList.add("Apr");
monthList.add("May");
monthList.add("Jun");
monthList.add("July");
monthList.add("Aug");
monthList.add("Sep");
monthList.add("Oct");
monthList.add("Nov");
monthList.add("Dec");

ArrayList dateList = new ArrayList();
int date = 0;
for(date=1;date<=31;date++){
dateList.add(date);
}
ArrayList yearList = new ArrayList();
int year= 0;
for(year=1980;year<=2020;year++){

yearList.add(year);
}

request.setAttribute("year",yearList);
request.setAttribute("date",dateList);
request.setAttribute("month",monthList);

RequestDispatcher rd = request.getRequestDispatcher("date.jsp");
rd.forward(request, response);
}

}


jsp...using jstl

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<html>
<body>
<center>
DOB :
<select name="datelist">
<c:forEach items="${date}" var="dat">
<option>${dat}</option>
</c:forEach>
</select>

<select name="monthlist">
<c:forEach items="${month}" var="mon">
<option>${mon}</option>
</c:forEach>
</select>

<select name="yearlist">
<c:forEach items="${year}" var="yr">
<option>${yr}</option>
</c:forEach>
</select>
</center>
</body>
</html>
 
reply
    Bookmark Topic Watch Topic
  • New Topic