matthew016
asked on
jsp question
Hi,
Im devlopping a website.
I have all the countries stored in my DB,
When a user wants to subscribe to the website, ha has to select his country.
I loaded the countries from my DB in memory in a "load-on-start" servlet.
I'm making a JSP file that gets the countries and display them in a combobox.
My question :
For every request,
the jsp file needs to get the countries and display them from a java class.
But I want the countries to be loaded in this combobox just once (not for every new request).
Thank you for any help.
Im devlopping a website.
I have all the countries stored in my DB,
When a user wants to subscribe to the website, ha has to select his country.
I loaded the countries from my DB in memory in a "load-on-start" servlet.
I'm making a JSP file that gets the countries and display them in a combobox.
My question :
For every request,
the jsp file needs to get the countries and display them from a java class.
But I want the countries to be loaded in this combobox just once (not for every new request).
Thank you for any help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi!
Store the country-names in an EJB Session Bean and let the server handle the load and cache of the data.
In that way country-names are stored in memory at startup and can be accessed quickly.
Regards,
Tomas Helgi
Store the country-names in an EJB Session Bean and let the server handle the load and cache of the data.
In that way country-names are stored in memory at startup and can be accessed quickly.
Regards,
Tomas Helgi
I think an EJB Session Bean for this task is like using a rocket launcher to kill a fly.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I store them in a session, the countries need to be loaded for each user no?
I want to load them just for once.
So actually I could load them in a static class and then access this class with a loop in the select.
Well actually I already did that and I tought it was a problem for performance and that
I could find a better solution.
>Perhaps build the select in an include
why?
I want to load them just for once.
So actually I could load them in a static class and then access this class with a loop in the select.
Well actually I already did that and I tought it was a problem for performance and that
I could find a better solution.
>Perhaps build the select in an include
why?
> I want to load them just for once.
thought u said you'd already loaded them?
> So actually I could load them in a static class and then access this class with a loop in the select.
should load them into a static class.
you should load them once and store them in the application context
>>Perhaps build the select in an include
>why?
In case you want to add the select to >1 pages
thought u said you'd already loaded them?
> So actually I could load them in a static class and then access this class with a loop in the select.
should load them into a static class.
you should load them once and store them in the application context
>>Perhaps build the select in an include
>why?
In case you want to add the select to >1 pages
ASKER
> I want to load them just for once.
>thought u said you'd already loaded them?
Actually I meant load them once from the application into my jsp page ...
I don't know if this affects performance because
at every request a big loop in the select is executed, and laod them from the class.
Then I have a loop to select language, and other loop.
U know what I mean ?
>thought u said you'd already loaded them?
Actually I meant load them once from the application into my jsp page ...
I don't know if this affects performance because
at every request a big loop in the select is executed, and laod them from the class.
Then I have a loop to select language, and other loop.
U know what I mean ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank u very much
As I said before.
Create a HttpSessionListener class and put a static java-class/object in that class which then can be accessed from all JSP pages. Doing this you load the data ONCE when the web-app is first loaded and destroyed when no users are browsing the web by counting active users.
Do it something like this :
import javax.servlet.http.HttpSes sionListen er;
import javax.servlet.http.HttpSes sionEvent;
public class SessionCounter implements HttpSessionListener {
private static int activeSessions = 0;
private static myCountry countries; // this class holds the countries ;)
private static boolean countries_loaded = false
public void sessionCreated(HttpSession Event se) {
activeSessions++;
if(activeSessions > 0 and !countries_loaded){
countries_loaded = true;
countries = new myCountry();
......
}
}
public void sessionDestroyed(HttpSessi onEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
Regards,
Tomas Helgi
Create a HttpSessionListener class and put a static java-class/object in that class which then can be accessed from all JSP pages. Doing this you load the data ONCE when the web-app is first loaded and destroyed when no users are browsing the web by counting active users.
Do it something like this :
import javax.servlet.http.HttpSes
import javax.servlet.http.HttpSes
public class SessionCounter implements HttpSessionListener {
private static int activeSessions = 0;
private static myCountry countries; // this class holds the countries ;)
private static boolean countries_loaded = false
public void sessionCreated(HttpSession
activeSessions++;
if(activeSessions > 0 and !countries_loaded){
countries_loaded = true;
countries = new myCountry();
......
}
}
public void sessionDestroyed(HttpSessi
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
Regards,
Tomas Helgi
Hmmm forgot one thing. ;)
import javax.servlet.http.HttpSes sionListen er;
import javax.servlet.http.HttpSes sionEvent;
public class SessionCounter implements HttpSessionListener {
private static int activeSessions = 0;
private static myCountry countries; // this class holds the countries ;)
private static boolean countries_loaded = false
public void sessionCreated(HttpSession Event se) {
activeSessions++;
if(activeSessions > 0 and !countries_loaded){
countries_loaded = true;
countries = new myCountry();
......
}
}
public void sessionDestroyed(HttpSessi onEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
public static myCountry getCountryClass(){
return countries;
}
}
Regards,
Tomas Helgi
import javax.servlet.http.HttpSes
import javax.servlet.http.HttpSes
public class SessionCounter implements HttpSessionListener {
private static int activeSessions = 0;
private static myCountry countries; // this class holds the countries ;)
private static boolean countries_loaded = false
public void sessionCreated(HttpSession
activeSessions++;
if(activeSessions > 0 and !countries_loaded){
countries_loaded = true;
countries = new myCountry();
......
}
}
public void sessionDestroyed(HttpSessi
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
public static myCountry getCountryClass(){
return countries;
}
}
Regards,
Tomas Helgi
ASKER
Thank u Tomas but I can't see why I should destroy the data when no sessions are active,
also I can't see any code that "destroys" the data like u say.
also I can't see any code that "destroys" the data like u say.
Perhaps build the select in an include