geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <>
Subject Re: Injecting EJB directly into a JSP
Date Wed, 02 Jul 2008 22:00:27 GMT
You can also declare resource-refs etc in your web.xml.

I think if you switched to jsf you'd be able to use annotations in  
your managed beans.  I can't say I understand how or if struts and jsf  

Thinking about the annotations-in-jsps issue I don't think we are  
likely to support it directly since it would either involve analyzing  
the jsp source (not going to happen IMO) or analyzing the jsp classes  
as they are loaded (which would involve reversing the philosophy  
behind geronimo deployment, namely we try to analyze everything at  
deploy time, not run time).  You can probably get them to work now by  
precompiling the jsps.  We might be able to support them by compiling  
jsps at deploy time.  However this would not work with hot  
redeployment of changed jsps.

david jencks

On Jul 2, 2008, at 12:22 PM, David Blevins wrote:

> On Jul 2, 2008, at 11:27 AM, purdticker wrote:
>> So what's the recommended solution to pulling data from database  
>> and giving
>> that ResultSet to jsp?  Currently, I'm using struts, I'd like to be  
>> able to
>> access my datasource from the action class and throw it in
>> request.setAttribute().
>> However, I can't inject ejb into action class. I also can't seem to  
>> inject
>> the datasource into action class...
>> 	@Resource(name="jdbc/EBSDS")
>> 	DataSource ds;
>> So how do I access my datasource from action class?  If geronimo  
>> doesn't
>> support this, what is recommended method?  I can't just create  
>> servlets for
>> everything.
> One easy trick is to create a single servlet class and annotate it  
> with all the things you need.  Since all injected resources also  
> wind up in JNDI and everything in the webapp shares the same JNDI  
> context, you can use it as a clever way to declare resources that  
> you need in your JSPs.
> For example, with the @Resource usage you have above, you can lookup  
> via JNDI in your JSP as follows:
>  InitialContext context = new InitialContext();
>  DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/ 
> EBSDS");
> -David

View raw message