You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Tiberiu DONDERA <ti...@hotmail.com> on 2000/12/04 18:11:38 UTC

XSP and ESQL

I'm almost sure that this is a topic that has already been discused, but I
could not find this piece of information anywhere :(

I am trying to create a simple login page using cocoon:

------- First page -----------
...
  <form action="login.xml">
    Username: <input name="login"> <br/>
    Password: <input type="password" name="pass"> <br/>
  </form>
----------------------------

Then I have, in login.xml:

-------------------
....

<xsp:page
  language="java"
  xmlns:esql="http://apache.org/cocoon/SQL/v2"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>

<page>
  <esql:execute-query>
    <esql:driver>...
    <esql:dburl>....
    <esql:user>....
    <esql:password>....  (these tags are correclty closed)

    <esql:query>
      select * from users where
            user_name='<xsp:expr>request.getParameter("login")</xsp:expr>'
        and password='<xsp:expr>request.getParameter("pass")</xsp:expr>'
    </esql:query>

    <esql:results>
      <user>
        <name><esql:get-string column="name"/></name>
      </user>
    </esql:results>
  </esql:execute-query>
</page>
</xsp:page>

My question is: how can I use the value retrieved by the ESQL afterwards, in
some XSP code?

username=???        // What should be here?
if (username.equals('anonymous')){
  <xsp:content>
     You are logged in as anonymous.
  </xsp:content>
}

Thank you for any help that you can give me. (references to where I can find
some examples, or just a simple example)

Tiberiu Dondera


Re: XSP and ESQL

Posted by Donald Ball <ba...@webslingerZ.com>.
On Tue, 5 Dec 2000, Tiberiu DONDERA wrote:

> Thank you for your help.
> I have, however, strange errors when using this piece of code:
>
>   <esql:execute-query>
>       ....
>     <esql:results>
>       <esql:row-results>
>         <xsp:logic>String username = <esql:get-string
> column="name"/>;</xsp:logic>
>       </esql:row-results>
>     </esql:results>
>   </esql:execute-query>
>
>       <username>
>         <xsp:expr>username</xsp:expr>
>       </username>
>
> The error
> -----------
> java.lang.Exception: XSP Java Compiler: Compilation failed for
> _logindone.java
> 235: Undefined variable: username
>           xspExpr(username, document)

try declaring the username variable in the root of your page:

<xsp:page>
  <page>
    <xsp:logic>String username;</xsp:logic>
    <esql:stuff>
      ...
    </esql:stuff>
    ...
  </page>
</xsp:page>

- donald


Re: XSP and ESQL

Posted by Tiberiu DONDERA <ti...@hotmail.com>.
Thank you for your help.
I have, however, strange errors when using this piece of code:

  <esql:execute-query>
      ....
    <esql:results>
      <esql:row-results>
        <xsp:logic>String username = <esql:get-string
column="name"/>;</xsp:logic>
      </esql:row-results>
    </esql:results>
  </esql:execute-query>

      <username>
        <xsp:expr>username</xsp:expr>
      </username>

The error
-----------
java.lang.Exception: XSP Java Compiler: Compilation failed for
_logindone.java
235: Undefined variable: username
          xspExpr(username, document)
                  ^
1 error

 at
org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(XSPJa
vaProcessor.java:141)
 at
org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java:489)
 at org.apache.cocoon.Engine.handle(Engine.java:359)
 at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
 at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
 at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection
(Ajp12ConnectionHandler.java:156)
 at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338
)
 at java.lang.Thread.run(Thread.java:484)
-----------

  IMHO (and I'm just making suppositions, because I don't have any knowledge
on the internals of Cocoon), this is because the class produced by the esql
is different from the class produced by xsp, so the code I produce with the
<xsp:logic> inside <esql:results> is not visible from the xsp produced
class, that produces my XML tree.
Is this a bug or is this the way that it should be? And if this is the way,
what is the proper way of solving this problem? (please note that the result
I have from the database may be used, after modifications in the java code,
in another sql query)

Also, the <esql:row-results> tag is getting copied in the result tree. Is
this normal?

You said something aboult upgrading my esql logicsheet from the cvs tree. I
am using Cocoon 1.8 (the 'out of the box' version). Is the upgrade really
necessary?

Thank you,
Tibi Dondera

For Mr. Robin Green:
  I'm sorry, I didn't make myself well understood (difficult english :)
  The username was just an example (not very well chosen, as you have
pointed out, because I could have retrieved it from the html post). The
problem was that I wanted to be able to retrieve some information from the
database and to be able to use it later inside another <xsp:logic> tag.

----- Original Message -----
From: Donald Ball <ba...@webslingerZ.com>
To: <co...@xml.apache.org>; Tiberiu DONDERA <ti...@yahoo.com>
Sent: Monday, December 04, 2000 8:20 PM
Subject: Re: XSP and ESQL


> On Mon, 4 Dec 2000, Tiberiu DONDERA wrote:
>
> > I'm almost sure that this is a topic that has already been discused, but
I
> > could not find this piece of information anywhere :(
>
> experiment, young grasshopper. and update your esql logicsheet to the
> latest cvs version - you're using an old version of the namespace.
>
>
> > My question is: how can I use the value retrieved by the ESQL
afterwards, in
> > some XSP code?
>
> <esql:results>
>   <esql:row-results>
>     <xsp:logic>String name = <esql:get-string column="name"/>;</xsp:logic>
>   </esql:row-results>
> </esql:results>
>
> > username=???        // What should be here?
> > if (username.equals('anonymous')){
> >   <xsp:content>
> >      You are logged in as anonymous.
> >   </xsp:content>
> > }
>
> <esql:results>
>   <esql:row-results>
>     <xsp:logic>if ("anonymous".equals(<esql:get-string column="name"/>)) {
>       <xsp:content>You are logged in as anonymous.</xsp:content>
>     </xsp:logic>
>   </esql:row-results>
> </esql:results>
>
> - donald
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>

Re: XSP and ESQL

Posted by Donald Ball <ba...@webslingerZ.com>.
On Mon, 4 Dec 2000, Tiberiu DONDERA wrote:

> I'm almost sure that this is a topic that has already been discused, but I
> could not find this piece of information anywhere :(

experiment, young grasshopper. and update your esql logicsheet to the
latest cvs version - you're using an old version of the namespace.


> My question is: how can I use the value retrieved by the ESQL afterwards, in
> some XSP code?

<esql:results>
  <esql:row-results>
    <xsp:logic>String name = <esql:get-string column="name"/>;</xsp:logic>
  </esql:row-results>
</esql:results>

> username=???        // What should be here?
> if (username.equals('anonymous')){
>   <xsp:content>
>      You are logged in as anonymous.
>   </xsp:content>
> }

<esql:results>
  <esql:row-results>
    <xsp:logic>if ("anonymous".equals(<esql:get-string column="name"/>)) {
      <xsp:content>You are logged in as anonymous.</xsp:content>
    </xsp:logic>
  </esql:row-results>
</esql:results>

- donald