You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Konstantina Stamopoulou <st...@intracom.gr> on 2002/04/03 10:36:41 UTC

How to take object from the Action to jsp

Hello,
My question might sound naive but I really eed your answer.

I'm storing an object in ServletContext with the following code :

   servlet.getServletContext().setAttribute("treemodel",root);
where root is an object of type Node(myclass). 

In my jsp I want to retrieve this object from the Servletontext so I do the following:

<%= new DirectoryModel((Node)servlet.getServletContext().getAttribute("treemodel") %>.

I'm wondering why I get the Exception:

org.apache.jasper.compiler.ParseException: C:\jakarta\jakarta-tomcat-3.2.3\webapps\teach\main_menu.jsp(77,99) Attribute treemodel has no value
	at org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:519)
	at org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.java:635)
	at org.apache.jasper.compiler.Parser$Tag.accept(Parser.java:798)

My problem is that I cannot handle this object as a javabean since I want to use the object as it is and not to get the values of its properties.

I would really appreciated your help.

Thank you,
Konstantina




Re: How to take object from the Action to jsp

Posted by Konstantina Stamopoulou <st...@intracom.gr>.
Thanx,
It finally  worked by using bean.

Konstantina
----- Original Message -----
From: "Enrique Rodriguez" <la...@telefonica.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, April 03, 2002 4:50 PM
Subject: RE: How to take object from the Action to jsp


> Hi Constantina,
>
> Instead of servlet.getServletContext().setAttribute("treemodel",root);
>
> I use request.setAttribute("treemodel",root);
>
> In the JSP, instead of
> DirectoryModel((Node)servlet.getServletContext().getAttribute("treemodel")
> %>.
>
> I use <bean:write name="treemodel" property="propertyOfNodeClass" /> to
> wirte one propierty into the generated html code,
>
> or <% DirectoryModel((Node)this.pageContext.getAttribute("treemodel"));
>
> Hope That Help, Enrique.
>
> _____________________________
> Enrique Rodriguez Lasterra
>
>
>
> > -----Mensaje original-----
> > De: Konstantina Stamopoulou [mailto:stak@intracom.gr]
> > Enviado el: miercoles, 03 de abril de 2002 10:37
> > Para: Struts Users Mailing List
> > Asunto: How to take object from the Action to jsp
> >
> >
> > Hello,
> > My question might sound naive but I really eed your answer.
> >
> > I'm storing an object in ServletContext with the following code :
> >
> >    servlet.getServletContext().setAttribute("treemodel",root);
> > where root is an object of type Node(myclass).
> >
> > In my jsp I want to retrieve this object from the Servletontext
> > so I do the following:
> >
> > <%= new
> > DirectoryModel((Node)servlet.getServletContext().getAttribute("tre
> emodel") %>.
> >
> > I'm wondering why I get the Exception:
> >
> > org.apache.jasper.compiler.ParseException:
> > C:\jakarta\jakarta-tomcat-3.2.3\webapps\teach\main_menu.jsp(77,99)
> >  Attribute treemodel has no value
> > at
> > org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader
> > .java:519)
> > at
> > org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.
> > java:635)
> > at org.apache.jasper.compiler.Parser$Tag.accept(Parser.java:798)
> >
> > My problem is that I cannot handle this object as a javabean
> > since I want to use the object as it is and not to get the values
> > of its properties.
> >
> > I would really appreciated your help.
> >
> > Thank you,
> > Konstantina
> >
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


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


RE: How to take object from the Action to jsp

Posted by Enrique Rodriguez <la...@telefonica.net>.
Hi Constantina,

Instead of servlet.getServletContext().setAttribute("treemodel",root);

I use request.setAttribute("treemodel",root);

In the JSP, instead of
DirectoryModel((Node)servlet.getServletContext().getAttribute("treemodel")
%>.

I use <bean:write name="treemodel" property="propertyOfNodeClass" /> to
wirte one propierty into the generated html code,

or <% DirectoryModel((Node)this.pageContext.getAttribute("treemodel"));

Hope That Help, Enrique.

_____________________________
Enrique Rodriguez Lasterra



> -----Mensaje original-----
> De: Konstantina Stamopoulou [mailto:stak@intracom.gr]
> Enviado el: miercoles, 03 de abril de 2002 10:37
> Para: Struts Users Mailing List
> Asunto: How to take object from the Action to jsp
>
>
> Hello,
> My question might sound naive but I really eed your answer.
>
> I'm storing an object in ServletContext with the following code :
>
>    servlet.getServletContext().setAttribute("treemodel",root);
> where root is an object of type Node(myclass).
>
> In my jsp I want to retrieve this object from the Servletontext
> so I do the following:
>
> <%= new
> DirectoryModel((Node)servlet.getServletContext().getAttribute("tre
emodel") %>.
>
> I'm wondering why I get the Exception:
>
> org.apache.jasper.compiler.ParseException:
> C:\jakarta\jakarta-tomcat-3.2.3\webapps\teach\main_menu.jsp(77,99)
>  Attribute treemodel has no value
> 	at
> org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader
> .java:519)
> 	at
> org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.
> java:635)
> 	at org.apache.jasper.compiler.Parser$Tag.accept(Parser.java:798)
>
> My problem is that I cannot handle this object as a javabean
> since I want to use the object as it is and not to get the values
> of its properties.
>
> I would really appreciated your help.
>
> Thank you,
> Konstantina
>
>
>
>


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


Re: How to take object from the Action to jsp

Posted by rob <ro...@fastmail.fm>.
.jsp pages have access to the a reference named application from which you can gain access to
objects stored in your servlet context.  I believe you should use the following method to access
context scoped objects within your jsp pages.

You can extract the reference to your "treemodel" with the following.

<%
Node root = (Node) application.getAttribute("treemodel");
%>
<%= new DirectoryModel(root) %>

Or your way

<%= new DirectoryModel((Node)application.getAttribute("treemodel")) %>



At 06:36 PM 4/3/2002, you wrote:
>Hello,
>My question might sound naive but I really eed your answer.
>
>I'm storing an object in ServletContext with the following code :
>
>   servlet.getServletContext().setAttribute("treemodel",root);
>where root is an object of type Node(myclass). 
>
>In my jsp I want to retrieve this object from the Servletontext so I do the following:
>
><%= new DirectoryModel((Node)servlet.getServletContext().getAttribute("treemodel") %>.
>
>I'm wondering why I get the Exception:
>
>org.apache.jasper.compiler.ParseException: C:\jakarta\jakarta-tomcat-3.2.3\webapps\teach\main_menu.jsp(77,99) Attribute treemodel has no value
>        at org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:519)
>        at org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.java:635)
>        at org.apache.jasper.compiler.Parser$Tag.accept(Parser.java:798)
>
>My problem is that I cannot handle this object as a javabean since I want to use the object as it is and not to get the values of its properties.
>
>I would really appreciated your help.
>
>Thank you,
>Konstantina



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