<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A JSP File Always Creates a Session</title>
	<atom:link href="http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Fri, 26 Feb 2010 19:39:40 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: AnikS</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1728</link>
		<dc:creator>AnikS</dc:creator>
		<pubDate>Mon, 04 Aug 2008 10:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1728</guid>
		<description>for creating session,
String uname = &quot;admin&quot;;
session.setAttribute(&quot;username&quot;,uname);

for retreiving the value from session.

String uname = (String)session.getAttribute(&quot;username&quot;);</description>
		<content:encoded><![CDATA[<p>for creating session,<br />
String uname = &#8220;admin&#8221;;<br />
session.setAttribute(&#8221;username&#8221;,uname);</p>
<p>for retreiving the value from session.</p>
<p>String uname = (String)session.getAttribute(&#8221;username&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1623</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Mon, 28 Jul 2008 18:22:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1623</guid>
		<description>&lt;blockquote&gt;...besides not having any info to store&lt;/blockquote&gt;

Not having anything to store would be the main point here. As in, when the jsps are simple, open, accessible by all, pages, we should make sure, that no session is automatically created, if not needed.

Now, there are perfectly good reasons to keep session on the server. There are also reasons not to. But this would be another post. When I mention a &quot;..share-nothing stateless architecture on the server-side..&quot;, it is a solution to scaling bigtime, for large, heavy load sites. You could keep session state at the client then, or keep it in the database.</description>
		<content:encoded><![CDATA[<blockquote><p>&#8230;besides not having any info to store</p></blockquote>
<p>Not having anything to store would be the main point here. As in, when the jsps are simple, open, accessible by all, pages, we should make sure, that no session is automatically created, if not needed.</p>
<p>Now, there are perfectly good reasons to keep session on the server. There are also reasons not to. But this would be another post. When I mention a &#8220;..share-nothing stateless architecture on the server-side..&#8221;, it is a solution to scaling bigtime, for large, heavy load sites. You could keep session state at the client then, or keep it in the database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1622</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 28 Jul 2008 17:12:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1622</guid>
		<description>I am a newbie to web development, so what are the reasons you wouldn&#039;t want to use a session to store info, besides not having any info to store?</description>
		<content:encoded><![CDATA[<p>I am a newbie to web development, so what are the reasons you wouldn&#8217;t want to use a session to store info, besides not having any info to store?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pfm</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1504</link>
		<dc:creator>pfm</dc:creator>
		<pubDate>Wed, 23 Jul 2008 21:25:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1504</guid>
		<description>I found why I was getting a session created despite the @page directive. I had a filter running that was doing this:
&lt;code&gt;
HttpSession session = ((HttpServletRequest) request).getSession();
&lt;/code&gt;
The getSession() method will create a session if there&#039;s not one already there.</description>
		<content:encoded><![CDATA[<p>I found why I was getting a session created despite the @page directive. I had a filter running that was doing this:<br />
<code><br />
HttpSession session = ((HttpServletRequest) request).getSession();<br />
</code><br />
The getSession() method will create a session if there&#8217;s not one already there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1486</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Wed, 23 Jul 2008 07:38:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1486</guid>
		<description>&lt;blockquote&gt;
This is worth creating an issue for the Jasper team.
&lt;/blockquote&gt;

Hmm, coming to think about it, I do &lt;em&gt;not&lt;/em&gt; think so :-)

I guess the implementation of Jasper, which simply creates a session up front when &lt;tt&gt;@page session=&quot;true&quot;&lt;/tt&gt; (or the default) is present, looks like a (good) trade-off in the compiler implementation (to me).

Let&#039;s think about what it would take, to create the session on demand... Given the JSP code below:

&lt;code&gt;
&lt;% if (something) {
      session.setAttribute(...); // use session here
   } else {
      // code that does NOT use session here
   }
%&gt;
&lt;/code&gt;

To have Jasper create a servlet, that only obtains a session, when (if) the code, in execution, actually reaches the block of code which use the session, Jasper would have to be a full blown Java compiler. It would have to parse scriptlet syntax, and determine type of session variable access, and ADD EXTRA CODE THERE, which obtained the session.

Would it not?

I think, with the knowledge on how Jasper forces early session creation, I can work-around it. I would simply extract the block of code, that use the session, into another JSP, and then have the main jsp file have &lt;tt&gt;session=&quot;false&quot;&lt;/tt&gt;. I would then dynamically include the other JSP, which uses a session.</description>
		<content:encoded><![CDATA[<blockquote><p>
This is worth creating an issue for the Jasper team.
</p></blockquote>
<p>Hmm, coming to think about it, I do <em>not</em> think so <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I guess the implementation of Jasper, which simply creates a session up front when <tt>@page session="true"</tt> (or the default) is present, looks like a (good) trade-off in the compiler implementation (to me).</p>
<p>Let&#8217;s think about what it would take, to create the session on demand&#8230; Given the JSP code below:</p>
<p><code><br />
&lt;% if (something) {<br />
      session.setAttribute(...); // use session here<br />
   } else {<br />
      // code that does NOT use session here<br />
   }<br />
%&gt;<br />
</code></p>
<p>To have Jasper create a servlet, that only obtains a session, when (if) the code, in execution, actually reaches the block of code which use the session, Jasper would have to be a full blown Java compiler. It would have to parse scriptlet syntax, and determine type of session variable access, and ADD EXTRA CODE THERE, which obtained the session.</p>
<p>Would it not?</p>
<p>I think, with the knowledge on how Jasper forces early session creation, I can work-around it. I would simply extract the block of code, that use the session, into another JSP, and then have the main jsp file have <tt>session="false"</tt>. I would then dynamically include the other JSP, which uses a session.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pfm</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1473</link>
		<dc:creator>pfm</dc:creator>
		<pubDate>Tue, 22 Jul 2008 19:31:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1473</guid>
		<description>I wanted to disable the session for my index.jsp/login.jsp pages and got to the same conclusion so far.

Despite I&#039;m adding a @page session=&quot;false&quot; directive in the JSPs, Tomcat is still reporting it has an active session (seeing it throw the Tomcat Manager).

Regarding to the compile error, I found that as a workaround you could check the value of &lt;code&gt;pageContext.getSession()&lt;/code&gt; which will return the session if it exists, or null if it doesn&#039;t.</description>
		<content:encoded><![CDATA[<p>I wanted to disable the session for my index.jsp/login.jsp pages and got to the same conclusion so far.</p>
<p>Despite I&#8217;m adding a @page session=&#8221;false&#8221; directive in the JSPs, Tomcat is still reporting it has an active session (seeing it throw the Tomcat Manager).</p>
<p>Regarding to the compile error, I found that as a workaround you could check the value of <code>pageContext.getSession()</code> which will return the session if it exists, or null if it doesn&#8217;t.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bóna Péter</title>
		<link>http://www.techper.net/2008/07/21/a-jsp-file-always-creates-a-session/comment-page-1/#comment-1466</link>
		<dc:creator>Bóna Péter</dc:creator>
		<pubDate>Tue, 22 Jul 2008 09:18:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=72#comment-1466</guid>
		<description>This is worth creating an issue for the Jasper team.</description>
		<content:encoded><![CDATA[<p>This is worth creating an issue for the Jasper team.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
