• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to arraylist value pass servlet action to JSP file

 
Arjun Palanichamy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the problem?
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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 <cut> to display each element in jsp.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic