• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem accessing Context Variable

 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following code in web.xml for initialising context parameter.

<context-param>
<param-name>myContextParamName</param-name>
<param-value>myContextParamValue</param-value>
</context-param>

I am trying to access it in JSTL using
${initParam["myContextParamName"]}
and it does not work.

I am not sure if the changes to web.xml are being recognized. I tried to use a JNDI name that was set up on the server as a resource in web.xml and even that is not recognized by the code. Restarting the server did not help.

Any ideas please ?

Thanks
vmrao
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and it does not work.


This is not helpful. Exactly how is it not working?
 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No output. As you know, JSTL does not show error on variables that do not exist. In this case, it was not able to find the context parameter defined in the web.xml file, I believe.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mahesh rao:

I am trying to access it in JSTL using
${initParam["myContextParamName"]}


The example you've given is not JSTL.
It is EL (Expression Language).

I just tried your example and it worked for me.
What container are you using (make and version)?
If you're using a JSP2.0 compliant container, post your entire web.xml file so we can verify that you've got the right schema declaration.
 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my web.xml .

<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
-->

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testApp</display-name>
<distributable/>

<context-param>
<param-name>
myContextParamName
</param-name>
<param-value>
myContextParamValue
</param-value>
</context-param>

</web-app>

We are using Sun Java System Application Server 8.1 ENTERPRISE Edition.

I tested the same code with Sun Java Studio Enterprise 8 integrated with Sun Java System Application Server Professional edition and it works fine.
I am not sure why it is not working with ENTERPRISE edition on our server. Looks like web.xml is not being considered by the server. I deleted web.xml and still I was able to deploy the application successfully.
 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I finally got it to work.

I found that the server is using the cached version of web.xml from generated\xml\j2ee-modules\appName directory. I got rid of the appName directory and it fixed the problem.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!