This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes JNDI problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JNDI problem" Watch "JNDI problem" New topic
Author

JNDI problem

satyro Bia
Greenhorn

Joined: Jan 11, 2011
Posts: 5
I have a problem,I have basically set jndi 2, 1 to access a db and the other to access a properties file so you can manage some parameters outside the application, the jdbc jndi is read properly, instead of the jndi properties file I should be in error.


first of all I will explain my setup, I have a tomcat server 5.5, Struts 1.3, winxp, sp1 helios eclipse.

then in web.xml I have these lines of code


instead of the server in the context.xml I have these lines

and finally to retrieve jndi use these instructions


db connection when the call goes alright, the db is read and written.
when I call the properties file back to me this error



Someone can help me? and sorry for my English
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You need to escape the backslash (I think)
url="C:\\deploy\\file.properties"
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

And no problems with the English, welcome to the Ranch
satyro Bia
Greenhorn

Joined: Jan 11, 2011
Posts: 5
David O'Meara wrote:You need to escape the backslash (I think)
url="C:\\deploy\\file.properties"



thanks for reply and for welcome.

I have already tried this solution, with the same result error, I tried also
url="file:///C:/deploy/file.properties"
and
url="file://C:/deploy/file.properties"
and
url="file:///C://deploy//file.properties"

I'm going crazy
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It looks like the first should be the correct one, do they all return the same error?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm also wondering if you should (could) store it as a String value (with escaped slashes) and then create a java.io.File from the String.
satyro Bia
Greenhorn

Joined: Jan 11, 2011
Posts: 5
David O'Meara wrote:It looks like the first should be the correct one, do they all return the same error?


same error...

David O'Meara wrote:I'm also wondering if you should (could) store it as a String value (with escaped slashes) and then create a java.io.File from the String.


you mean this?
String fi = (String)PortableRemoteObject.narrow(
env.lookup("url/fileprop"), String.class);

I tried now and the result is always that mistake
Victor Hugo M Machado
Greenhorn

Joined: Jan 11, 2011
Posts: 22

you can´t do this ?



simple as that..

why not?
satyro Bia
Greenhorn

Joined: Jan 11, 2011
Posts: 5
Victor Hugo Muniz Machado wrote:you can´t do this ?



simple as that..

why not?


for jdbc there are no problem.

i try this


getting the same error
Victor Hugo M Machado
Greenhorn

Joined: Jan 11, 2011
Posts: 22

take a look..

http://www.coderanch.com/t/87532/Tomcat/configure-JNDI-URL-resource
Victor Hugo M Machado
Greenhorn

Joined: Jan 11, 2011
Posts: 22

look here too
http://help.sap.com/saphelp_nw70/helpdata/en/15/6d56f65fb59e4db97253c89c5cfefd/content.htm

Example
Resource of Type javax.mail.Session
To get a resource of type javax.mail.Session the web.xml descriptor can be as follows:

<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Resource of Type java.net.URL
We need to redirect an HTTP request to a URL available as JNDI resource. The following source code retrieves the corresponding java.net.URL resource and redirects the client request to it.

InitialContext context = new InitialContext();
URL yahoo=(URL)context.lookup("java:comp/env/url/Yahoo.com");
response.sendRedirect(yahoo.toString());

We describe the reference to that resource in the web.xml as follows:
<resource-ref>
<res-ref-name>url/Yahoo.com</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
</resource-ref>

We describe the reference to that resource in the web-j2ee-engine.xml as follows:
<resource-ref>
<res-ref-name>url/Yahoo.com</res-ref-name>
<res-link>http://www.yahoo.com</res-link>
</resource-ref>


satyro Bia
Greenhorn

Joined: Jan 11, 2011
Posts: 5
thank you for your reply, I solved this way.

context.xml in the server I have declared an Environment



and then I return the value in this way



I did not add anything in web.xml.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JNDI problem
 
Similar Threads
Error in configuring JDBC Datasource
Tomcat can't find a JDBC JNDI resource
help in my first DBCP
naming.NameNotFoundException
JNDI in entry in context.xml and web.xml