You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christofer Dutz <ch...@danet.de> on 2000/09/01 13:57:14 UTC
Re: nullpointerexception when trying to session.setAttribute
> I'm having a problem setting a session variable - I'm getting a
> nullpointerexception back from cocoon on the line where I do the
> setAttribute. It's a pretty basic example, I've taken a look at the .java
> file in my servlet engine's repository and the code looks ok there too.
> Here's my code:
>
> <xsp:logic><![CDATA[
> if (checkSecurity(request))
> {
>
>
> boolean useridExists =
> false;
>
> try
> {
> String s =
> (String)session.getAttribute("userid");
As far as I see it. the getSession function doesn't throw an exception when
there is no "userid"-object for this session.
I do the session-checking like this :
<xsp:logic><![CDATA[
if( session.getAttribute( "user") != null) {
String user = ( ( User) session.getAttribute( "user")).getUserId(); ]]>
<xsp:content>
<response>Eingelogt als : <xsp:expr>user</xsp:expr></response>
</xsp:content>
<![CDATA[ }
if( session.getAttribute( "loginError") != null) {
String error = ( String) session.getAttribute(
"loginError"); ]]><xsp:content>
<error><xsp:expr>error</xsp:expr></error>
</xsp:content>
<![CDATA[ } ]]></xsp:logic>
and it works fine for me ...
By dooing it the way yo do. this code is always executed
> useridExists
> = true;
When you now try to access the "userid"-object you certainly get an
exception.
> }
> catch (Exception e)
> {
> useridExists
> = false;
> }
>
> if ( !useridExists &&
> request.getParameter("userid") != null)
> {
> String s =
> "117";
>
> session.setAttribute("userid2", "abc"); //generates nullpointer exception
> ????
> }
> ]]>
> <xsl:copy>
>
> <xsl:apply-templates/>
> </xsl:copy>
>
> }
> else
> {
> <securityexception/>
>
> <xsp:expr>writeToLog("security exception: referrer_ip=" +
> request.getHeader("REMOTE_ADDR").trim() + " local_ip=" +
> request.getHeader("LOCAL_ADDR").trim());</xsp:expr>
>
> <xsp:content><xsp:expr>request.getHeader("REMOTE_ADDR").trim()
>
</xsp:expr><xsp:expr>request.getHeader("LOCAL_ADDR").trim()</xsp:expr></xsp:
> content>
> }
> </xsp:logic>
Regards
Christofer Dutz