• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to arraylist value pass servlet action to JSP file

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..

I have some list of email in array list in servlet action file i want to send and print jsp input textarea box.

here paste my servlet action class code :
package addressbook;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

import weebersexception.SearchException;

public class MailAddressAction extends HttpServlet {

private static final Logger log = Logger.getLogger(MailAddressAction.class);

ArrayList contactlist;

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
MailAddressImporter mailaddress = new MailAddressImporter();

try {

log.info("Enter the addressbook action page");

contactlist = mailaddress.mail(req);
log.info(contactlist);

req.setAttribute("contact_details", contactlist);
forward("/classifieds/mailaddress.jsp",req,res);

} catch (SearchException e) {
log.info(e.getMessage());
req.setAttribute("iserror", "yes");
req.setAttribute("errors", e.getMessage());
forward("/classifieds/mailaddress.jsp",req,res);
}
}

public String forward(String url, HttpServletRequest req,
HttpServletResponse res) {

RequestDispatcher dis = req.getRequestDispatcher(url);

try {
dis.forward(req, res);
} catch (ServletException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
}

return url;

}

}
********************************************


please any can help solve this problem.

advance thanks.
Arjun
 
Sheriff
Posts: 67664
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
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Sheriff
Posts: 67664
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
What's the problem?
 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Arjun Palanichamy:
Hi..

I have some list of email in array list in servlet action file i want to send and print jsp input textarea box.

here paste my servlet action class code :
package addressbook;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

import weebersexception.SearchException;

public class MailAddressAction extends HttpServlet {

private static final Logger log = Logger.getLogger(MailAddressAction.class);

ArrayList contactlist;

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
MailAddressImporter mailaddress = new MailAddressImporter();

try {

log.info("Enter the addressbook action page");

contactlist = mailaddress.mail(req);
log.info(contactlist);

req.setAttribute("contact_details", contactlist);
forward("/classifieds/mailaddress.jsp",req,res);

} catch (SearchException e) {
log.info(e.getMessage());
req.setAttribute("iserror", "yes");
req.setAttribute("errors", e.getMessage());
forward("/classifieds/mailaddress.jsp",req,res);
}
}

public String forward(String url, HttpServletRequest req,
HttpServletResponse res) {

RequestDispatcher dis = req.getRequestDispatcher(url);

try {
dis.forward(req, res);
} catch (ServletException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
}

return url;

}

}
********************************************


please any can help solve this problem.

advance thanks.
Arjun



.........You can make use of getAttribute() of request to get the value of arraylist and iterate it displaying values inside a scriplet or use JSTL - <c:forEach> to iterate and <c:out> to display each element in jsp.
 
Just the other day, I was thinking ... about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic