Suppose I got class:
import java.io.Serializable;
public class UrlEntry implements Serializable
{
private String shortUrl;
private String longUrl;
private long clicks;
public UrlEntry(String shortUrl, String longUrl, long clicks)
{
this.shortUrl = shortUrl;
this.longUrl = longUrl;
this.clicks = clicks;
}
public String getShortUrl()
{
return shortUrl;
}
public void setShortUrl(String shortUrl)
{
this.shortUrl = shortUrl;
}
public String getLongUrl()
{
return longUrl;
}
public void setLongUrl(String longUrl)
{
this.longUrl = longUrl;
}
public long getClicks()
{
return clicks;
}
public void setClicks(long clicks)
{
this.clicks = clicks;
}
public UrlEntry(){}
}
This is code from controller servlet
HttpSession session = request.getSession(true);
ArrayList<UrlEntry> list = new ArrayList<UrlEntry>();
list.add(new UrlEntry("abc","site1.com",1));
list.add(new UrlEntry("def","site2.com",2));
list.add(new UrlEntry("ghi","site3.com",3));
session.setAttribute("urls", list);
response.sendRedirect("index.jsp");
This is part of code from index.jsp this works well
<%=request.getSession().getAttribute("urls")%>
but this doesn't work:
<%=(ArrayList<UrlEntry>)request.getSession().getAttribute("urls")%>
with error
UrlEntry cannot be resolved to a type
<%=(ArrayList<UrlEntry>)request.getSession().getAttribute("urls")%>
What am I doing wrong? Should I declare UrlEntry as serializable? Maybe some problems with the constructor?