Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI problem

 
satyro Bia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to escape the backslash (I think)
url="C:\\deploy\\file.properties"
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And no problems with the English, welcome to the Ranch
 
satyro Bia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the first should be the correct one, do they all return the same error?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can´t do this ?



simple as that..

why not?
 
satyro Bia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Eclipse IDE Java Oracle
 
Victor Hugo M Machado
Greenhorn
Posts: 22
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic