• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

help with application variables to store the list of names code

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a select list of 300+ names. The way I want to do it is to have that list built and cached on startup so that the html that is displaying that list will be done on startup not each time the page is rendered.

so what I am trying to do is use application variables to store the list of names

Not sure whats wrong with this code.
public class SomeList extends HttpServlet{

private String listOfSome;
public void init(){

}

public void service(HttpServletRequest req,HttpServletResponse resp){

private void getSome() throws DataLayerException
{
Connection Connection = null;
Connection = ConnectionFactory.getConnection();
synchronized(Connection)
{
try
{
listOfSome = "";
Statement Statement = Connection.createStatement();
ResultSet rs = Statement.executeQuery("SELECT row1, row2, row3, row4, row5 FROM table WHERE row6=aa order by row3");
String row5="";
while (rs.next())
{
if(rs.getString(4) != null){city = rs.getString(4);}
listOfDealer += "<option value=" + rs.getString(1) + ">"+ rs.getString(2) +","+ rs.getString(3) +","+ row5 +","+ rs.getString(5) + "</option>";
}
if (rs !=null) rs.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}


public String getListOfSome() throws DataLayerException {
getSome();
this.getServletConfig().getServletContext().setAttribute("listOfSome",listOfSome);
//return listOfSome;
}
}
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on the jsp page the result is null
application.getInitParameter("listOfStuff")
 
Sheriff
Posts: 67752
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
Why would you try to get an attribute with getInitParameter()? Use getAttribute().
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I did that too, both getAttribute and getInitParameter return null.
[ February 01, 2005: Message edited by: Didier McGillis ]
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is wrong, it doesn't set anything inside the session:

this.getServletConfig().getServletContext().setAttribute("listOfSome",listOfSome);

you need something like req.getSession().setAttribute("yourID", obj);
[ February 01, 2005: Message edited by: Kashif Riaz ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kashif Riaz:
I think this is wrong, it doesn't set anything inside the session:

this.getServletConfig().getServletContext().setAttribute("listOfSome",listOfSome);

you need something like req.getSession().setAttribute("yourID", obj);

[ February 01, 2005: Message edited by: Kashif Riaz ]




He said he wants the variables to be Context or Application Scoped. There is no need to create session variables for this.
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah that would be some honkin session var
 
Didier McGillis
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay here is whats I did last nigth, a bit late.

public class StuffList extends HttpServlet{

private String listOfStuff;

public void init(ServletConfig config) throws ServletException{
Connection Connection = null;
Connection = ConnectionFactory.getConnection();
synchronized(Connection)
{
try
{
listOfStuff = "";
Statement Statement = Connection.createStatement();
ResultSet rs = Statement.executeQuery("SELECT row1, row2, row3, row4, row5 FROM table WHERE row6=aa order by row3");
String city="";
while (rs.next())
{
if(rs.getString(4) != null){city = rs.getString(4);}
listOfStuff += "<option value=" + rs.getString(1) + ">"+ rs.getString(2) +","+ rs.getString(3) +","+ city +","+ rs.getString(5) + "</option>";
}
config.getServletContext().setAttribute("listOfStuff",listOfStuff);
if (rs !=null) rs.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

public void service(ServletRequest req,
ServletResponse res)
throws ServletException,
java.io.IOException{

}
}

somethings just not right, like its asking for a DataLayerException to throw.
[ February 02, 2005: Message edited by: Didier McGillis ]
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic