Hi,
I'm trying to make a start on the MVC Model 2 approach with a simplish JSP/Servlet application. I'm looking for tips for best practice.
I have a main controller servlet, and various JSP views. When the controller servlet is first called (let's say we pass action="start" in the request to the servlet to let it know that this is the entry point), I can gather info from the request about the user. I only want to do this once, then store this information and make it available to the JSP views as required.
I could store this info in session variables, but I thought it might be tidier to store it in a bean object. However, my experience of using beans is very basic.
If I initialise a bean in the servlet, what lifespan will it have? Just the session? (There is a new instance of the servlet for every session...?) To access the bean from the JSP page, would I use the JSP useBean tag, and if so, with what scope? Or should I save the bean to the session in the servlet, then retrieve it from the session in the JSP pages?
Also, is it reasonable to just intialise the bean when the web application is first accessed (action="start"), or should I be checking at every stage to see if the bean is initialised, and if not, start the initialisation procedure?
Sorry if these are basic issues, but i don't have a good overview of the process.
Thanks,
Mike
I'm trying to make a start on the MVC Model 2 approach with a simplish JSP/Servlet application. I'm looking for tips for best practice.
I have a main controller servlet, and various JSP views. When the controller servlet is first called (let's say we pass action="start" in the request to the servlet to let it know that this is the entry point), I can gather info from the request about the user. I only want to do this once, then store this information and make it available to the JSP views as required.
I could store this info in session variables, but I thought it might be tidier to store it in a bean object. However, my experience of using beans is very basic.
If I initialise a bean in the servlet, what lifespan will it have? Just the session? (There is a new instance of the servlet for every session...?) To access the bean from the JSP page, would I use the JSP useBean tag, and if so, with what scope? Or should I save the bean to the session in the servlet, then retrieve it from the session in the JSP pages?
Also, is it reasonable to just intialise the bean when the web application is first accessed (action="start"), or should I be checking at every stage to see if the bean is initialised, and if not, start the initialisation procedure?
Sorry if these are basic issues, but i don't have a good overview of the process.
Thanks,
Mike