You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Truhann van der Poel <Tr...@datavoice.co.za> on 2001/06/06 16:24:56 UTC

Cocoon and Sessions

I am new to Cocoon and sessions. Are using C1.8.2.

Can anybody send a beginner sample (or pointer to help-documentation) to
setup/save/retrieve variables from a session.  
All the <session:xxx> tags in my xsp page create NullPointer's.

Truhann

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: Cocoon and Sessions

Posted by declan kelly <de...@yahoo.com>.
I bet your error is caused by not including the create
session directive in the namespaces declaration.

Anyway here's a very simple little login thingy, it
takes stuff from a form and logs you in or redirects
you back.

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="login-html.xsl"
type="text/xsl"?>
<?xml-stylesheet href="login-wml.xsl" type="text/xsl"
media="wap"?>
<?xml-stylesheet href="page-chtml.xsl" type="text/xsl"
media="imode"?>
<xsp:page language="java"
xmlns:esql="http://apache.org/cocoon/SQL/v2"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:session="http://www.apache.org/1999/XSP/Session"
create-session="true">
	<xsp:logic>
		String sqlstring = "";
		String username ="";
		String passwd = "";
		String UID="";
		final static char APOS = (char)39;
		final static char BLANK = (char)32;		
	</xsp:logic>
	<page>
		<xsp:logic>			
			username = request.getParameter("username");
			passwd    = request.getParameter("passwd");
			
			(username.replace(APOS,BLANK)).trim();
			(passwd.replace(APOS,BLANK)).trim();
			
			<!--Get rid of case sensitivity-->
			username.toLowerCase();
			passwd.toLowerCase();
			
			sqlstring = "SELECT * FROM users WHERE user_name =
'" + username + "'";
		</xsp:logic>
		<esql:connection>
			<esql:pool>project</esql:pool>
			<esql:execute-query>
				<esql:query>
					<xsp:expr>sqlstring</xsp:expr>
				</esql:query>
				<esql:results>
					<esql:row-results>
						<xsp:logic>
					if(passwd.equals(<esql:get-string
column="passwd"/>))
						{
							<!--Set the session variable UID to the users
UID and jump to their page-->
							<session:set-attribute name="UID">
								<esql:get-string column="uid"/>
							</session:set-attribute>
						
						
response.sendRedirect(response.encodeRedirectURL("menupage.xml"));
						}
					else
						response.sendRedirect("login.xml?error=1");	
				</xsp:logic>
					</esql:row-results>
				</esql:results>
				<esql:no-results>
				
<xsp:logic>response.sendRedirect("login.xml?error=1");</xsp:logic>
				</esql:no-results>
			</esql:execute-query>
		</esql:connection>
		<link href="login.xml">Try Again</link>
	</page>
</xsp:page>


Then on every page which you should be logged in to
see include this 


<!--#####################################-->
<!--Check if User has logged in-->
	try{<session:get-attribute name="UID"/>;}
	catch (NullPointerException e)
	   {
		response.sendRedirect("login.xml");
	   }
<!--#####################################-->




--- Truhann van der Poel
<Tr...@datavoice.co.za> wrote:
> I am new to Cocoon and sessions. Are using C1.8.2.
> 
> Can anybody send a beginner sample (or pointer to
> help-documentation) to
> setup/save/retrieve variables from a session.  
> All the <session:xxx> tags in my xsp page create
> NullPointer's.
> 
> Truhann
> 
>
---------------------------------------------------------------------
> Please check that your question has not already been
> answered in the
> FAQ before posting.
> <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail:
> <co...@xml.apache.org>
> For additional commands, e-mail:
> <co...@xml.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


WMLScript

Posted by Antonio Parolini <to...@employer.com.br>.
Hi,
I know this is off topic, but anyone know any good WML mailing list out
there ?

thanks...

- Tony

> -----Original Message-----
> From: Truhann van der Poel [mailto:Truhann.vanderPoel@datavoice.co.za]
> Sent: quarta-feira, 6 de junho de 2001 11:25
> To: cocoon-users@xml.apache.org
> Subject: Cocoon and Sessions
>
>
> I am new to Cocoon and sessions. Are using C1.8.2.
>
> Can anybody send a beginner sample (or pointer to help-documentation) to
> setup/save/retrieve variables from a session.
> All the <session:xxx> tags in my xsp page create NullPointer's.
>
> Truhann
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>