aspose file tools*
The moose likes JSP and the fly likes How to arraylist value pass servlet action  to JSP file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to arraylist value pass servlet action  to JSP file" Watch "How to arraylist value pass servlet action  to JSP file" New topic
Author

How to arraylist value pass servlet action to JSP file

Arjun Palanichamy
Ranch Hand

Joined: Jul 15, 2006
Posts: 51
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

Joined: Jan 10, 2002
Posts: 61433
    
  67

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

What's the problem?
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

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.


Thanks & Regards
Sidharth Pallai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to arraylist value pass servlet action to JSP file