geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purdticker <core...@rocketmail.com>
Subject Re: Injecting EJB directly into a JSP
Date Wed, 02 Jul 2008 20:24:44 GMT

You are a GENIOUS :P  Haha, it works great, thanks!


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 this message in context: http://www.nabble.com/Injecting-EJB-directly-into-a-JSP-tp18228470s134p18245998.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Mime
View raw message