Hi,
I m new in Servlet side programming.i want to pass the ArrayList from Servlet to JSP page.how do i do this? below is what i tried.it allways pass Null value.My java file name is Login.java and my jsp file name is FirstJSP.jsp.
FirstJSP.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>`
<%@ page import="java.util.ArrayList" %>
<!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>Insert title here</title>`
</head>
<body>
<%
ArrayList <String> str1=new ArrayList <String>();
if (request.getSession().getAttribute("str1") != null) {
str1 = (ArrayList ) request.getSession().getAttribute("str1");
out.println(str1);
}
%>
</body>
</html>
Login.java
package com;
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 javax.servlet.http.HttpSession;
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
public Login() {
super();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ArrayList <String> str1=new ArrayList <String>();
HttpSession session = request.getSession(true);
response.setContentType("text/html");
try
{
str1.add("String1");
str1.add("String2");
request.setAttribute("str1", str1);
String destination="/FirstJSP.jsp"; //If authentication fails///////////
RequestDispatcher rd = getServletContext().getRequestDispatcher(destinati on);
rd.forward(request, response);
}
catch (Exception e)
{
throw new ServletException(e.toString());
}
}
}