I want to create a global session in JSP to be used in all servlets and JSP files, as in PHP with instructions Used:
& lt ;? Php session_start (); ? & Gt;
Tried with it:
HiPiation s = request.getSession ();
And set it works, but I pass several passes from one to another in another JSP file.
How can I do this?
You can use the ServletContext listener to maintain the variable of ServletContext for all your application listener. , So that when you can execute some code, start the application to start the attributes (on the ServletContext) and when it will end (before its centered).
Public Ultimate Class applies MyAppListener ServletContextListener {public zero reference start (ServletContextEvent event) {System.out.println (""); CharlotteTontextSerleContact = Event. JetServletContax (); ServletContext.setAttribute ("Some Attribute", "Hello World!"); } Public Zero ReferenceDrust (Steractontex Event Event) {System.out.println ("The app is finished."); }} If you are using Java EE 5, you will see web.xml & lt; Listener & gt; The listener should be configured in & Lt; Audience category & gt; Mypackage.listener.MyAppListener & lt; / Listener Category & gt; & Lt; / Listener & gt;
Comments
Post a Comment