Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is session in Java?
    text
    copied!<p>So far I understand Httpsession concepts in Java. </p> <pre><code> HttpSession ses = req.getSession(true); </code></pre> <p>will create a session object, according to the request.</p> <pre><code>setAttribute("String", object); </code></pre> <p>will, bind the 'String', and value with the Session object.</p> <pre><code>getAttribute("String"); </code></pre> <p>will return an object associated with the string, specified.</p> <p>What I am not able to understand is: I am creating a session object like <code>HttpSession ses = req.getSession(true);</code> and setting a name for it by calling <code>setAttribute("String", object);</code>. Here, This code resides inside the server. For every person, when he tries to login the same code in the server will be executed. <code>setAttribute("String", object);</code> in this method the string value is a constant one. So, each session object created will be binded by the same string which I have provided. When I try to retrieve the string to validate his session or while logout action taken the <code>getAttribute("String");</code> ll return the same constant string value(Am I right!!?? Actually I don't know, I'm just thinking of its logic of execution). Then, how can I be able to invalidate. </p> <p>I saw this type of illustration in all of the tutorials on the WEB. Is it the actual way to set that attribute? Or, real application developers will give a variable in the "String" field to set it dynamically</p> <p><code>(ie. session.setAttribut(userName, userName); //Setting the String Dynamically.. I dono is it right or not.)</code></p> <p>And my final question is</p> <pre><code>WebContext ctx = WebContextFactory.get(); request = ctx.getHttpServletRequest(); </code></pre> <p>What do the two lines above do? What will be stored in ctx &amp; request? <code>HttpSession ses = req.getSession(true);</code> will creates new session means. What value stored in ses.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload