Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » context.xml
context.xml [message #141277] Thu, 29 September 2005 08:27 Go to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
Hello,
I know this has been asked a thousand times before, but I still seem to have
problems with my servlet's context.xml .
I created a context.xml file in my project's WebContent/META-INF directory.
In that xml file I've put something like:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Parameter name="P1" value="bla"/>
<Parameter name="P2" value="bli"/>
<Parameter name="P3" value="blo"/>
</Context>

but in my servlet's init method, the configuration I get contains no
parameters.
I've tried do "publish" manually, deploy/undeploy the module.
I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
What may be the cause of this?
Thanks,
Zohar.
Re: context.xml [message #141329 is a reply to message #141277] Thu, 29 September 2005 15:27 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
Zohar,

On the todo list is to improve the error handing if there is a problem
reading the context.xml. Currently, there is no error reported and
including the context information is skipped. The XML you show below
looks fine (works copy & pasted in a webapp in my workspace). The one
mysterious way I am aware of to cause this problem is to be running
Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
beginning of the file. The Crimson XML parser obtained from the 1.4.x
JRE or JDK doesn't handle this BOM and erroneously considers it an error.

If this is the case, you can open the context.xml with the Text Editor.
Set the encoding to be US-ASCII or ISO-8859-1 and three funny
characters should appear at the beginning of the file, which can be
deleted. Then set the encoding back to what it was. Hopefully that is
the problem.

Cheers,
Larry


Zohar wrote:
> Hello,
> I know this has been asked a thousand times before, but I still seem to have
> problems with my servlet's context.xml .
> I created a context.xml file in my project's WebContent/META-INF directory.
> In that xml file I've put something like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Context>
> <Parameter name="P1" value="bla"/>
> <Parameter name="P2" value="bli"/>
> <Parameter name="P3" value="blo"/>
> </Context>
>
> but in my servlet's init method, the configuration I get contains no
> parameters.
> I've tried do "publish" manually, deploy/undeploy the module.
> I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
> What may be the cause of this?
> Thanks,
> Zohar.
>
>
Re: context.xml [message #142566 is a reply to message #141329] Thu, 06 October 2005 12:49 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
I checked and there is no BOM in the beginning? any other possible causes
for this? can I check some logs for this somewhere?

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dhh145$2m6$1@news.eclipse.org...
> Zohar,
>
> On the todo list is to improve the error handing if there is a problem
> reading the context.xml. Currently, there is no error reported and
> including the context information is skipped. The XML you show below
> looks fine (works copy & pasted in a webapp in my workspace). The one
> mysterious way I am aware of to cause this problem is to be running
> Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
> beginning of the file. The Crimson XML parser obtained from the 1.4.x JRE
> or JDK doesn't handle this BOM and erroneously considers it an error.
>
> If this is the case, you can open the context.xml with the Text Editor.
> Set the encoding to be US-ASCII or ISO-8859-1 and three funny characters
> should appear at the beginning of the file, which can be deleted. Then
> set the encoding back to what it was. Hopefully that is the problem.
>
> Cheers,
> Larry
>
>
> Zohar wrote:
>> Hello,
>> I know this has been asked a thousand times before, but I still seem to
>> have problems with my servlet's context.xml .
>> I created a context.xml file in my project's WebContent/META-INF
>> directory. In that xml file I've put something like:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Context>
>> <Parameter name="P1" value="bla"/>
>> <Parameter name="P2" value="bli"/>
>> <Parameter name="P3" value="blo"/>
>> </Context>
>>
>> but in my servlet's init method, the configuration I get contains no
>> parameters.
>> I've tried do "publish" manually, deploy/undeploy the module.
>> I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>> What may be the cause of this?
>> Thanks,
>> Zohar.
>>
Re: context.xml [message #143089 is a reply to message #142566] Tue, 11 October 2005 13:06 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
Sorry for the delayed response. I was away on vacation. Did you
discover the problem, or is it still a mystery? Out side of the BOM,
I'm only aware of XML syntax errors causing this, which I'm sure you've
already checked.

Larry

Zohar wrote:
> I checked and there is no BOM in the beginning? any other possible causes
> for this? can I check some logs for this somewhere?
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:dhh145$2m6$1@news.eclipse.org...
>
>>Zohar,
>>
>>On the todo list is to improve the error handing if there is a problem
>>reading the context.xml. Currently, there is no error reported and
>>including the context information is skipped. The XML you show below
>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>mysterious way I am aware of to cause this problem is to be running
>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>beginning of the file. The Crimson XML parser obtained from the 1.4.x JRE
>>or JDK doesn't handle this BOM and erroneously considers it an error.
>>
>>If this is the case, you can open the context.xml with the Text Editor.
>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny characters
>>should appear at the beginning of the file, which can be deleted. Then
>>set the encoding back to what it was. Hopefully that is the problem.
>>
>>Cheers,
>>Larry
>>
>>
>>Zohar wrote:
>>
>>>Hello,
>>>I know this has been asked a thousand times before, but I still seem to
>>>have problems with my servlet's context.xml .
>>>I created a context.xml file in my project's WebContent/META-INF
>>>directory. In that xml file I've put something like:
>>>
>>><?xml version="1.0" encoding="UTF-8"?>
>>><Context>
>>> <Parameter name="P1" value="bla"/>
>>> <Parameter name="P2" value="bli"/>
>>> <Parameter name="P3" value="blo"/>
>>></Context>
>>>
>>>but in my servlet's init method, the configuration I get contains no
>>>parameters.
>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>What may be the cause of this?
>>>Thanks,
>>>Zohar.
>>>
>
>
Re: context.xml [message #143135 is a reply to message #143089] Tue, 11 October 2005 16:45 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
Thanks for the reply (hope you had a nice vacation).
Haven't nailed this yet...
The file is valid (used XML Spy to check it).
No logs to look at?

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:digdcj$8kp$1@news.eclipse.org...
> Sorry for the delayed response. I was away on vacation. Did you discover
> the problem, or is it still a mystery? Out side of the BOM, I'm only
> aware of XML syntax errors causing this, which I'm sure you've already
> checked.
>
> Larry
>
> Zohar wrote:
>> I checked and there is no BOM in the beginning? any other possible causes
>> for this? can I check some logs for this somewhere?
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dhh145$2m6$1@news.eclipse.org...
>>
>>>Zohar,
>>>
>>>On the todo list is to improve the error handing if there is a problem
>>>reading the context.xml. Currently, there is no error reported and
>>>including the context information is skipped. The XML you show below
>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>mysterious way I am aware of to cause this problem is to be running
>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>JRE or JDK doesn't handle this BOM and erroneously considers it an error.
>>>
>>>If this is the case, you can open the context.xml with the Text Editor.
>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny characters
>>>should appear at the beginning of the file, which can be deleted. Then
>>>set the encoding back to what it was. Hopefully that is the problem.
>>>
>>>Cheers,
>>>Larry
>>>
>>>
>>>Zohar wrote:
>>>
>>>>Hello,
>>>>I know this has been asked a thousand times before, but I still seem to
>>>>have problems with my servlet's context.xml .
>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>directory. In that xml file I've put something like:
>>>>
>>>><?xml version="1.0" encoding="UTF-8"?>
>>>><Context>
>>>> <Parameter name="P1" value="bla"/>
>>>> <Parameter name="P2" value="bli"/>
>>>> <Parameter name="P3" value="blo"/>
>>>></Context>
>>>>
>>>>but in my servlet's init method, the configuration I get contains no
>>>>parameters.
>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>What may be the cause of this?
>>>>Thanks,
>>>>Zohar.
>>>>
>>
Re: context.xml [message #143153 is a reply to message #143135] Tue, 11 October 2005 17:38 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
To this point, I have been assuming that "in my servlet's init method,
the configuration I get contains no parameters" means that the <Context>
element in the server.xml under
".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf" doesn't
include the <Parameter> child elements. Is this the case, or is it that
your servlet just doesn't see them? If the server.xml includes the
parameter elements, what does your init method look like?

Larry

Zohar wrote:
> Thanks for the reply (hope you had a nice vacation).
> Haven't nailed this yet...
> The file is valid (used XML Spy to check it).
> No logs to look at?
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:digdcj$8kp$1@news.eclipse.org...
>
>>Sorry for the delayed response. I was away on vacation. Did you discover
>>the problem, or is it still a mystery? Out side of the BOM, I'm only
>>aware of XML syntax errors causing this, which I'm sure you've already
>>checked.
>>
>>Larry
>>
>>Zohar wrote:
>>
>>>I checked and there is no BOM in the beginning? any other possible causes
>>>for this? can I check some logs for this somewhere?
>>>
>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>news:dhh145$2m6$1@news.eclipse.org...
>>>
>>>
>>>>Zohar,
>>>>
>>>>On the todo list is to improve the error handing if there is a problem
>>>>reading the context.xml. Currently, there is no error reported and
>>>>including the context information is skipped. The XML you show below
>>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>>mysterious way I am aware of to cause this problem is to be running
>>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>>JRE or JDK doesn't handle this BOM and erroneously considers it an error.
>>>>
>>>>If this is the case, you can open the context.xml with the Text Editor.
>>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny characters
>>>>should appear at the beginning of the file, which can be deleted. Then
>>>>set the encoding back to what it was. Hopefully that is the problem.
>>>>
>>>>Cheers,
>>>>Larry
>>>>
>>>>
>>>>Zohar wrote:
>>>>
>>>>
>>>>>Hello,
>>>>>I know this has been asked a thousand times before, but I still seem to
>>>>>have problems with my servlet's context.xml .
>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>directory. In that xml file I've put something like:
>>>>>
>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>><Context>
>>>>> <Parameter name="P1" value="bla"/>
>>>>> <Parameter name="P2" value="bli"/>
>>>>> <Parameter name="P3" value="blo"/>
>>>>></Context>
>>>>>
>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>parameters.
>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>What may be the cause of this?
>>>>>Thanks,
>>>>>Zohar.
>>>>>
>>>
>
Re: context.xml [message #144016 is a reply to message #143153] Sun, 16 October 2005 12:34 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
In my servlet I have:
-----------------------------8<------------------------------------------
public void init(ServletConfig config) throws ServletException {
...
Enumeration paramNames = config.getInitParameterNames();
while(paramNames.hasMoreElements()){
String sCurrElemName = (String) paramNames.nextElement();
String sCurrElemValue = config.getInitParameter(sCurrElemName);
System.out.println(sCurrElemName+"="+sCurrElemValue);
}
}
-----------------------------8<------------------------------------------

Nothing gets printed, and when running in debug mode I can see that the
enumeration is empty.

I deleted the project and recreated it, but it didn't help.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:digta3$2fo$1@news.eclipse.org...
> To this point, I have been assuming that "in my servlet's init method, the
> configuration I get contains no parameters" means that the <Context>
> element in the server.xml under
> ".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf" doesn't include
> the <Parameter> child elements. Is this the case, or is it that your
> servlet just doesn't see them? If the server.xml includes the parameter
> elements, what does your init method look like?
>
> Larry
>
> Zohar wrote:
>> Thanks for the reply (hope you had a nice vacation).
>> Haven't nailed this yet...
>> The file is valid (used XML Spy to check it).
>> No logs to look at?
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:digdcj$8kp$1@news.eclipse.org...
>>
>>>Sorry for the delayed response. I was away on vacation. Did you
>>>discover the problem, or is it still a mystery? Out side of the BOM, I'm
>>>only aware of XML syntax errors causing this, which I'm sure you've
>>>already checked.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I checked and there is no BOM in the beginning? any other possible
>>>>causes for this? can I check some logs for this somewhere?
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>
>>>>
>>>>>Zohar,
>>>>>
>>>>>On the todo list is to improve the error handing if there is a problem
>>>>>reading the context.xml. Currently, there is no error reported and
>>>>>including the context information is skipped. The XML you show below
>>>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>>>mysterious way I am aware of to cause this problem is to be running
>>>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>>>JRE or JDK doesn't handle this BOM and erroneously considers it an
>>>>>error.
>>>>>
>>>>>If this is the case, you can open the context.xml with the Text Editor.
>>>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>characters should appear at the beginning of the file, which can be
>>>>>deleted. Then set the encoding back to what it was. Hopefully that is
>>>>>the problem.
>>>>>
>>>>>Cheers,
>>>>>Larry
>>>>>
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>Hello,
>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>to have problems with my servlet's context.xml .
>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>directory. In that xml file I've put something like:
>>>>>>
>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>><Context>
>>>>>> <Parameter name="P1" value="bla"/>
>>>>>> <Parameter name="P2" value="bli"/>
>>>>>> <Parameter name="P3" value="blo"/>
>>>>>></Context>
>>>>>>
>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>parameters.
>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>What may be the cause of this?
>>>>>>Thanks,
>>>>>>Zohar.
>>>>>>
>>>>
>>
Re: context.xml [message #144081 is a reply to message #143153] Mon, 17 October 2005 07:46 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
I now have one project where the context.xml's content is passed to the
servlet's init method, and another where it doesn't... What differences
should I look for between the two?

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:digta3$2fo$1@news.eclipse.org...
> To this point, I have been assuming that "in my servlet's init method, the
> configuration I get contains no parameters" means that the <Context>
> element in the server.xml under
> ".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf" doesn't include
> the <Parameter> child elements. Is this the case, or is it that your
> servlet just doesn't see them? If the server.xml includes the parameter
> elements, what does your init method look like?
>
> Larry
>
> Zohar wrote:
>> Thanks for the reply (hope you had a nice vacation).
>> Haven't nailed this yet...
>> The file is valid (used XML Spy to check it).
>> No logs to look at?
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:digdcj$8kp$1@news.eclipse.org...
>>
>>>Sorry for the delayed response. I was away on vacation. Did you
>>>discover the problem, or is it still a mystery? Out side of the BOM, I'm
>>>only aware of XML syntax errors causing this, which I'm sure you've
>>>already checked.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I checked and there is no BOM in the beginning? any other possible
>>>>causes for this? can I check some logs for this somewhere?
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>
>>>>
>>>>>Zohar,
>>>>>
>>>>>On the todo list is to improve the error handing if there is a problem
>>>>>reading the context.xml. Currently, there is no error reported and
>>>>>including the context information is skipped. The XML you show below
>>>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>>>mysterious way I am aware of to cause this problem is to be running
>>>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>>>JRE or JDK doesn't handle this BOM and erroneously considers it an
>>>>>error.
>>>>>
>>>>>If this is the case, you can open the context.xml with the Text Editor.
>>>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>characters should appear at the beginning of the file, which can be
>>>>>deleted. Then set the encoding back to what it was. Hopefully that is
>>>>>the problem.
>>>>>
>>>>>Cheers,
>>>>>Larry
>>>>>
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>Hello,
>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>to have problems with my servlet's context.xml .
>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>directory. In that xml file I've put something like:
>>>>>>
>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>><Context>
>>>>>> <Parameter name="P1" value="bla"/>
>>>>>> <Parameter name="P2" value="bli"/>
>>>>>> <Parameter name="P3" value="blo"/>
>>>>>></Context>
>>>>>>
>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>parameters.
>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>What may be the cause of this?
>>>>>>Thanks,
>>>>>>Zohar.
>>>>>>
>>>>
>>
Re: context.xml [message #144090 is a reply to message #143153] Mon, 17 October 2005 07:59 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
I looked at
<workspace> \.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\se rver.xml
and it contains a "Context" element for the problematic context with all of
the "parameter" subelements in it.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:digta3$2fo$1@news.eclipse.org...
> To this point, I have been assuming that "in my servlet's init method, the
> configuration I get contains no parameters" means that the <Context>
> element in the server.xml under
> ".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf" doesn't include
> the <Parameter> child elements. Is this the case, or is it that your
> servlet just doesn't see them? If the server.xml includes the parameter
> elements, what does your init method look like?
>
> Larry
>
> Zohar wrote:
>> Thanks for the reply (hope you had a nice vacation).
>> Haven't nailed this yet...
>> The file is valid (used XML Spy to check it).
>> No logs to look at?
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:digdcj$8kp$1@news.eclipse.org...
>>
>>>Sorry for the delayed response. I was away on vacation. Did you
>>>discover the problem, or is it still a mystery? Out side of the BOM, I'm
>>>only aware of XML syntax errors causing this, which I'm sure you've
>>>already checked.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I checked and there is no BOM in the beginning? any other possible
>>>>causes for this? can I check some logs for this somewhere?
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>
>>>>
>>>>>Zohar,
>>>>>
>>>>>On the todo list is to improve the error handing if there is a problem
>>>>>reading the context.xml. Currently, there is no error reported and
>>>>>including the context information is skipped. The XML you show below
>>>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>>>mysterious way I am aware of to cause this problem is to be running
>>>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>>>JRE or JDK doesn't handle this BOM and erroneously considers it an
>>>>>error.
>>>>>
>>>>>If this is the case, you can open the context.xml with the Text Editor.
>>>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>characters should appear at the beginning of the file, which can be
>>>>>deleted. Then set the encoding back to what it was. Hopefully that is
>>>>>the problem.
>>>>>
>>>>>Cheers,
>>>>>Larry
>>>>>
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>Hello,
>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>to have problems with my servlet's context.xml .
>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>directory. In that xml file I've put something like:
>>>>>>
>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>><Context>
>>>>>> <Parameter name="P1" value="bla"/>
>>>>>> <Parameter name="P2" value="bli"/>
>>>>>> <Parameter name="P3" value="blo"/>
>>>>>></Context>
>>>>>>
>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>parameters.
>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>What may be the cause of this?
>>>>>>Thanks,
>>>>>>Zohar.
>>>>>>
>>>>
>>
Re: context.xml [message #144140 is a reply to message #144016] Mon, 17 October 2005 14:24 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
Your parameters will appear as if your web.xml contained the equivalent
context parameters. To read them, I believe you want:

Enumeration paramNames = getServletContext().getInitParameterNames();

You are currently trying to the servlet's init parameters.

Larry

Zohar wrote:
> In my servlet I have:
> -----------------------------8<------------------------------------------
> public void init(ServletConfig config) throws ServletException {
> ...
> Enumeration paramNames = config.getInitParameterNames();
> while(paramNames.hasMoreElements()){
> String sCurrElemName = (String) paramNames.nextElement();
> String sCurrElemValue = config.getInitParameter(sCurrElemName);
> System.out.println(sCurrElemName+"="+sCurrElemValue);
> }
> }
> -----------------------------8<------------------------------------------
>
> Nothing gets printed, and when running in debug mode I can see that the
> enumeration is empty.
>
> I deleted the project and recreated it, but it didn't help.
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:digta3$2fo$1@news.eclipse.org...
>
>>To this point, I have been assuming that "in my servlet's init method, the
>>configuration I get contains no parameters" means that the <Context>
>>element in the server.xml under
>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf" doesn't include
>>the <Parameter> child elements. Is this the case, or is it that your
>>servlet just doesn't see them? If the server.xml includes the parameter
>>elements, what does your init method look like?
>>
>>Larry
>>
>>Zohar wrote:
>>
>>>Thanks for the reply (hope you had a nice vacation).
>>>Haven't nailed this yet...
>>>The file is valid (used XML Spy to check it).
>>>No logs to look at?
>>>
>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>news:digdcj$8kp$1@news.eclipse.org...
>>>
>>>
>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>discover the problem, or is it still a mystery? Out side of the BOM, I'm
>>>>only aware of XML syntax errors causing this, which I'm sure you've
>>>>already checked.
>>>>
>>>>Larry
>>>>
>>>>Zohar wrote:
>>>>
>>>>
>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>causes for this? can I check some logs for this somewhere?
>>>>>
>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>>Zohar,
>>>>>>
>>>>>>On the todo list is to improve the error handing if there is a problem
>>>>>>reading the context.xml. Currently, there is no error reported and
>>>>>>including the context information is skipped. The XML you show below
>>>>>>looks fine (works copy & pasted in a webapp in my workspace). The one
>>>>>>mysterious way I am aware of to cause this problem is to be running
>>>>>>Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at the
>>>>>>beginning of the file. The Crimson XML parser obtained from the 1.4.x
>>>>>>JRE or JDK doesn't handle this BOM and erroneously considers it an
>>>>>>error.
>>>>>>
>>>>>>If this is the case, you can open the context.xml with the Text Editor.
>>>>>>Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>>characters should appear at the beginning of the file, which can be
>>>>>>deleted. Then set the encoding back to what it was. Hopefully that is
>>>>>>the problem.
>>>>>>
>>>>>>Cheers,
>>>>>>Larry
>>>>>>
>>>>>>
>>>>>>Zohar wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Hello,
>>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>>to have problems with my servlet's context.xml .
>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>directory. In that xml file I've put something like:
>>>>>>>
>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>><Context>
>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>></Context>
>>>>>>>
>>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>>parameters.
>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>What may be the cause of this?
>>>>>>>Thanks,
>>>>>>>Zohar.
>>>>>>>
>>>>>
>
>
Re: context.xml [message #144385 is a reply to message #144140] Wed, 19 October 2005 08:21 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
I'm a bit confused then (this may be a servlet / tomcat general question).
What are the options of configuring my servlet and how do I do this with
WTP? I want these parameters to be set by the servlet's deployer, not the
writer (me).
I read getServletContext's javadoc and it says that it is the same object as
the one passed to init - so what's the difference?
Thanks again,
Zohar.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj0c6k$k46$1@news.eclipse.org...
> Your parameters will appear as if your web.xml contained the equivalent
> context parameters. To read them, I believe you want:
>
> Enumeration paramNames = getServletContext().getInitParameterNames();
>
> You are currently trying to the servlet's init parameters.
>
> Larry
>
> Zohar wrote:
>> In my servlet I have:
>> -----------------------------8<------------------------------------------
>> public void init(ServletConfig config) throws ServletException {
>> ...
>> Enumeration paramNames = config.getInitParameterNames();
>> while(paramNames.hasMoreElements()){
>> String sCurrElemName = (String) paramNames.nextElement();
>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>> }
>> }
>> -----------------------------8<------------------------------------------
>>
>> Nothing gets printed, and when running in debug mode I can see that the
>> enumeration is empty.
>>
>> I deleted the project and recreated it, but it didn't help.
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:digta3$2fo$1@news.eclipse.org...
>>
>>>To this point, I have been assuming that "in my servlet's init method,
>>>the configuration I get contains no parameters" means that the <Context>
>>>element in the server.xml under
>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>include the <Parameter> child elements. Is this the case, or is it that
>>>your servlet just doesn't see them? If the server.xml includes the
>>>parameter elements, what does your init method look like?
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>Thanks for the reply (hope you had a nice vacation).
>>>>Haven't nailed this yet...
>>>>The file is valid (used XML Spy to check it).
>>>>No logs to look at?
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>
>>>>
>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>discover the problem, or is it still a mystery? Out side of the BOM,
>>>>>I'm only aware of XML syntax errors causing this, which I'm sure you've
>>>>>already checked.
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Zohar,
>>>>>>>
>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>reported and including the context information is skipped. The XML
>>>>>>>you show below
>>>>>>>looks fine (works copy & pasted in a webapp in my workspace). The
>>>>>>>one mysterious way I am aware of to cause this problem is to be
>>>>>>>running Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at
>>>>>>>the beginning of the file. The Crimson XML parser obtained from the
>>>>>>>1.4.x JRE or JDK doesn't handle this BOM and erroneously considers it
>>>>>>>an error.
>>>>>>>
>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>>>characters should appear at the beginning of the file, which can be
>>>>>>>deleted. Then set the encoding back to what it was. Hopefully that
>>>>>>>is the problem.
>>>>>>>
>>>>>>>Cheers,
>>>>>>>Larry
>>>>>>>
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Hello,
>>>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>>>to have problems with my servlet's context.xml .
>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>
>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>><Context>
>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>></Context>
>>>>>>>>
>>>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>>>parameters.
>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>What may be the cause of this?
>>>>>>>>Thanks,
>>>>>>>>Zohar.
>>>>>>>>
>>>>>>
>>
Re: context.xml [message #144438 is a reply to message #144385] Wed, 19 October 2005 14:29 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
In web.xml you can have:

<web-app>
<context-param>
<param-name>P1</param-name>
<param-value>bla</param-value>
</context-param>
....
<servlet>
<servlet-name>SomeServlet</servlet-name>
<servlet-class>some.pkg.SomeServlet</servlet-class>
<init-param>
<param-name>P2</param-name>
<param-value>bli</param-value>
</init-param>
</servlet>
....
</web-app>

Using "getServletContext().getInitParameterNames()" will give you "P1",
where your "config.getInitParameterNames()" will give you "P2". As a
bonus feature of Tomcat, your <Parameter> elements in the context.xml
create the equivalent of <context-parameter> elements found in the
web.xml. Thus, you can specify them without modifying the webapp's
web.xml. The only problem is that your code below is trying to read
<init-param> info instead of <context-param> info, and as a result, is
unable to see your context parameters.

HTH.

Larry

Zohar wrote:
> I'm a bit confused then (this may be a servlet / tomcat general question).
> What are the options of configuring my servlet and how do I do this with
> WTP? I want these parameters to be set by the servlet's deployer, not the
> writer (me).
> I read getServletContext's javadoc and it says that it is the same object as
> the one passed to init - so what's the difference?
> Thanks again,
> Zohar.
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:dj0c6k$k46$1@news.eclipse.org...
>
>>Your parameters will appear as if your web.xml contained the equivalent
>>context parameters. To read them, I believe you want:
>>
>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>
>>You are currently trying to the servlet's init parameters.
>>
>>Larry
>>
>>Zohar wrote:
>>
>>>In my servlet I have:
>>>-----------------------------8<------------------------------------------
>>>public void init(ServletConfig config) throws ServletException {
>>> ...
>>> Enumeration paramNames = config.getInitParameterNames();
>>> while(paramNames.hasMoreElements()){
>>> String sCurrElemName = (String) paramNames.nextElement();
>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>> }
>>>}
>>>-----------------------------8<------------------------------------------
>>>
>>>Nothing gets printed, and when running in debug mode I can see that the
>>>enumeration is empty.
>>>
>>>I deleted the project and recreated it, but it didn't help.
>>>
>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>news:digta3$2fo$1@news.eclipse.org...
>>>
>>>
>>>>To this point, I have been assuming that "in my servlet's init method,
>>>>the configuration I get contains no parameters" means that the <Context>
>>>>element in the server.xml under
>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>include the <Parameter> child elements. Is this the case, or is it that
>>>>your servlet just doesn't see them? If the server.xml includes the
>>>>parameter elements, what does your init method look like?
>>>>
>>>>Larry
>>>>
>>>>Zohar wrote:
>>>>
>>>>
>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>Haven't nailed this yet...
>>>>>The file is valid (used XML Spy to check it).
>>>>>No logs to look at?
>>>>>
>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>discover the problem, or is it still a mystery? Out side of the BOM,
>>>>>>I'm only aware of XML syntax errors causing this, which I'm sure you've
>>>>>>already checked.
>>>>>>
>>>>>>Larry
>>>>>>
>>>>>>Zohar wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>
>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Zohar,
>>>>>>>>
>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>reported and including the context information is skipped. The XML
>>>>>>>>you show below
>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace). The
>>>>>>>>one mysterious way I am aware of to cause this problem is to be
>>>>>>>>running Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark at
>>>>>>>>the beginning of the file. The Crimson XML parser obtained from the
>>>>>>>>1.4.x JRE or JDK doesn't handle this BOM and erroneously considers it
>>>>>>>>an error.
>>>>>>>>
>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three funny
>>>>>>>>characters should appear at the beginning of the file, which can be
>>>>>>>>deleted. Then set the encoding back to what it was. Hopefully that
>>>>>>>>is the problem.
>>>>>>>>
>>>>>>>>Cheers,
>>>>>>>>Larry
>>>>>>>>
>>>>>>>>
>>>>>>>>Zohar wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Hello,
>>>>>>>>>I know this has been asked a thousand times before, but I still seem
>>>>>>>>>to have problems with my servlet's context.xml .
>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>
>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>><Context>
>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>></Context>
>>>>>>>>>
>>>>>>>>>but in my servlet's init method, the configuration I get contains no
>>>>>>>>>parameters.
>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>What may be the cause of this?
>>>>>>>>>Thanks,
>>>>>>>>>Zohar.
>>>>>>>>>
>>>>>>>
>
Re: context.xml [message #144456 is a reply to message #144438] Wed, 19 October 2005 14:48 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
So when I deploy my WAR file and indicate where its configuration file is,
it is equivalent to your P1 example? because it has a slightly different
syntax (similar to the one in context.xml).

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj5l94$f4c$1@news.eclipse.org...
> In web.xml you can have:
>
> <web-app>
> <context-param>
> <param-name>P1</param-name>
> <param-value>bla</param-value>
> </context-param>
> ...
> <servlet>
> <servlet-name>SomeServlet</servlet-name>
> <servlet-class>some.pkg.SomeServlet</servlet-class>
> <init-param>
> <param-name>P2</param-name>
> <param-value>bli</param-value>
> </init-param>
> </servlet>
> ...
> </web-app>
>
> Using "getServletContext().getInitParameterNames()" will give you "P1",
> where your "config.getInitParameterNames()" will give you "P2". As a
> bonus feature of Tomcat, your <Parameter> elements in the context.xml
> create the equivalent of <context-parameter> elements found in the
> web.xml. Thus, you can specify them without modifying the webapp's
> web.xml. The only problem is that your code below is trying to read
> <init-param> info instead of <context-param> info, and as a result, is
> unable to see your context parameters.
>
> HTH.
>
> Larry
>
> Zohar wrote:
>> I'm a bit confused then (this may be a servlet / tomcat general
>> question).
>> What are the options of configuring my servlet and how do I do this with
>> WTP? I want these parameters to be set by the servlet's deployer, not the
>> writer (me).
>> I read getServletContext's javadoc and it says that it is the same object
>> as the one passed to init - so what's the difference?
>> Thanks again,
>> Zohar.
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dj0c6k$k46$1@news.eclipse.org...
>>
>>>Your parameters will appear as if your web.xml contained the equivalent
>>>context parameters. To read them, I believe you want:
>>>
>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>
>>>You are currently trying to the servlet's init parameters.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>In my servlet I have:
>>>>-----------------------------8<------------------------------------------
>>>>public void init(ServletConfig config) throws ServletException {
>>>> ...
>>>> Enumeration paramNames = config.getInitParameterNames();
>>>> while(paramNames.hasMoreElements()){
>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>> }
>>>>}
>>>>-----------------------------8<------------------------------------------
>>>>
>>>>Nothing gets printed, and when running in debug mode I can see that the
>>>>enumeration is empty.
>>>>
>>>>I deleted the project and recreated it, but it didn't help.
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>
>>>>
>>>>>To this point, I have been assuming that "in my servlet's init method,
>>>>>the configuration I get contains no parameters" means that the
>>>>><Context> element in the server.xml under
>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>the parameter elements, what does your init method look like?
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>Haven't nailed this yet...
>>>>>>The file is valid (used XML Spy to check it).
>>>>>>No logs to look at?
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>discover the problem, or is it still a mystery? Out side of the BOM,
>>>>>>>I'm only aware of XML syntax errors causing this, which I'm sure
>>>>>>>you've already checked.
>>>>>>>
>>>>>>>Larry
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>
>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Zohar,
>>>>>>>>>
>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>reported and including the context information is skipped. The XML
>>>>>>>>>you show below
>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace). The
>>>>>>>>>one mysterious way I am aware of to cause this problem is to be
>>>>>>>>>running Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark
>>>>>>>>>at the beginning of the file. The Crimson XML parser obtained from
>>>>>>>>>the 1.4.x JRE or JDK doesn't handle this BOM and erroneously
>>>>>>>>>considers it an error.
>>>>>>>>>
>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>funny characters should appear at the beginning of the file, which
>>>>>>>>>can be deleted. Then set the encoding back to what it was.
>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>
>>>>>>>>>Cheers,
>>>>>>>>>Larry
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>Zohar wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>Hello,
>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>
>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>><Context>
>>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>>></Context>
>>>>>>>>>>
>>>>>>>>>>but in my servlet's init method, the configuration I get contains
>>>>>>>>>>no parameters.
>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>Thanks,
>>>>>>>>>>Zohar.
>>>>>>>>>>
>>>>>>>>
>>
Re: context.xml [message #144465 is a reply to message #144456] Wed, 19 October 2005 15:03 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
I'm not exactly sure what is meant by "because it has a slightly
different syntax". What Tomcat would create internally for:

<Parameter name="P1" value="bla"/>

in your context.xml is identical to what it would create for:

<context-param>
<param-name>P1</param-name>
<param-value>bla</param-value>
</context-param>

in a web.xml. It's two ways of doing the same thing. Perhaps that's
what you mean by your last statement.

Larry

Zohar wrote:
> So when I deploy my WAR file and indicate where its configuration file is,
> it is equivalent to your P1 example? because it has a slightly different
> syntax (similar to the one in context.xml).
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:dj5l94$f4c$1@news.eclipse.org...
>
>>In web.xml you can have:
>>
>><web-app>
>> <context-param>
>> <param-name>P1</param-name>
>> <param-value>bla</param-value>
>> </context-param>
>>...
>> <servlet>
>> <servlet-name>SomeServlet</servlet-name>
>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>> <init-param>
>> <param-name>P2</param-name>
>> <param-value>bli</param-value>
>> </init-param>
>> </servlet>
>>...
>></web-app>
>>
>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>where your "config.getInitParameterNames()" will give you "P2". As a
>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>create the equivalent of <context-parameter> elements found in the
>>web.xml. Thus, you can specify them without modifying the webapp's
>>web.xml. The only problem is that your code below is trying to read
>><init-param> info instead of <context-param> info, and as a result, is
>>unable to see your context parameters.
>>
>>HTH.
>>
>>Larry
>>
>>Zohar wrote:
>>
>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>question).
>>>What are the options of configuring my servlet and how do I do this with
>>>WTP? I want these parameters to be set by the servlet's deployer, not the
>>>writer (me).
>>>I read getServletContext's javadoc and it says that it is the same object
>>>as the one passed to init - so what's the difference?
>>>Thanks again,
>>>Zohar.
>>>
>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>
>>>
>>>>Your parameters will appear as if your web.xml contained the equivalent
>>>>context parameters. To read them, I believe you want:
>>>>
>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>
>>>>You are currently trying to the servlet's init parameters.
>>>>
>>>>Larry
>>>>
>>>>Zohar wrote:
>>>>
>>>>
>>>>>In my servlet I have:
>>>>>-----------------------------8<------------------------------------------
>>>>>public void init(ServletConfig config) throws ServletException {
>>>>> ...
>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>> while(paramNames.hasMoreElements()){
>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>> }
>>>>>}
>>>>>-----------------------------8<------------------------------------------
>>>>>
>>>>>Nothing gets printed, and when running in debug mode I can see that the
>>>>>enumeration is empty.
>>>>>
>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>
>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>>To this point, I have been assuming that "in my servlet's init method,
>>>>>>the configuration I get contains no parameters" means that the
>>>>>><Context> element in the server.xml under
>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>>the parameter elements, what does your init method look like?
>>>>>>
>>>>>>Larry
>>>>>>
>>>>>>Zohar wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>Haven't nailed this yet...
>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>No logs to look at?
>>>>>>>
>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>discover the problem, or is it still a mystery? Out side of the BOM,
>>>>>>>>I'm only aware of XML syntax errors causing this, which I'm sure
>>>>>>>>you've already checked.
>>>>>>>>
>>>>>>>>Larry
>>>>>>>>
>>>>>>>>Zohar wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>>
>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>Zohar,
>>>>>>>>>>
>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>reported and including the context information is skipped. The XML
>>>>>>>>>>you show below
>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace). The
>>>>>>>>>>one mysterious way I am aware of to cause this problem is to be
>>>>>>>>>>running Eclipse with a 1.4.x JRE or JDK and have a Byte-Order-Mark
>>>>>>>>>>at the beginning of the file. The Crimson XML parser obtained from
>>>>>>>>>>the 1.4.x JRE or JDK doesn't handle this BOM and erroneously
>>>>>>>>>>considers it an error.
>>>>>>>>>>
>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>funny characters should appear at the beginning of the file, which
>>>>>>>>>>can be deleted. Then set the encoding back to what it was.
>>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>>
>>>>>>>>>>Cheers,
>>>>>>>>>>Larry
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>Zohar wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>Hello,
>>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>>
>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>><Context>
>>>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>>>></Context>
>>>>>>>>>>>
>>>>>>>>>>>but in my servlet's init method, the configuration I get contains
>>>>>>>>>>>no parameters.
>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>Thanks,
>>>>>>>>>>>Zohar.
>>>>>>>>>>>
>>>>>>>>>
>
>
Re: context.xml [message #144474 is a reply to message #144465] Wed, 19 October 2005 15:07 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
Probably did. Any good place to read about all this?

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj5n8c$ia9$1@news.eclipse.org...
> I'm not exactly sure what is meant by "because it has a slightly different
> syntax". What Tomcat would create internally for:
>
> <Parameter name="P1" value="bla"/>
>
> in your context.xml is identical to what it would create for:
>
> <context-param>
> <param-name>P1</param-name>
> <param-value>bla</param-value>
> </context-param>
>
> in a web.xml. It's two ways of doing the same thing. Perhaps that's what
> you mean by your last statement.
>
> Larry
>
> Zohar wrote:
>> So when I deploy my WAR file and indicate where its configuration file
>> is, it is equivalent to your P1 example? because it has a slightly
>> different syntax (similar to the one in context.xml).
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dj5l94$f4c$1@news.eclipse.org...
>>
>>>In web.xml you can have:
>>>
>>><web-app>
>>> <context-param>
>>> <param-name>P1</param-name>
>>> <param-value>bla</param-value>
>>> </context-param>
>>>...
>>> <servlet>
>>> <servlet-name>SomeServlet</servlet-name>
>>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>>> <init-param>
>>> <param-name>P2</param-name>
>>> <param-value>bli</param-value>
>>> </init-param>
>>> </servlet>
>>>...
>>></web-app>
>>>
>>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>>where your "config.getInitParameterNames()" will give you "P2". As a
>>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>>create the equivalent of <context-parameter> elements found in the
>>>web.xml. Thus, you can specify them without modifying the webapp's
>>>web.xml. The only problem is that your code below is trying to read
>>><init-param> info instead of <context-param> info, and as a result, is
>>>unable to see your context parameters.
>>>
>>>HTH.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>>question).
>>>>What are the options of configuring my servlet and how do I do this with
>>>>WTP? I want these parameters to be set by the servlet's deployer, not
>>>>the writer (me).
>>>>I read getServletContext's javadoc and it says that it is the same
>>>>object as the one passed to init - so what's the difference?
>>>>Thanks again,
>>>>Zohar.
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>>
>>>>
>>>>>Your parameters will appear as if your web.xml contained the equivalent
>>>>>context parameters. To read them, I believe you want:
>>>>>
>>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>>
>>>>>You are currently trying to the servlet's init parameters.
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>In my servlet I have:
>>>>>>-----------------------------8<------------------------------------------
>>>>>>public void init(ServletConfig config) throws ServletException {
>>>>>> ...
>>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>>> while(paramNames.hasMoreElements()){
>>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>>> }
>>>>>>}
>>>>>>-----------------------------8<------------------------------------------
>>>>>>
>>>>>>Nothing gets printed, and when running in debug mode I can see that
>>>>>>the enumeration is empty.
>>>>>>
>>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>To this point, I have been assuming that "in my servlet's init
>>>>>>>method, the configuration I get contains no parameters" means that
>>>>>>>the <Context> element in the server.xml under
>>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>>>the parameter elements, what does your init method look like?
>>>>>>>
>>>>>>>Larry
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>>Haven't nailed this yet...
>>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>>No logs to look at?
>>>>>>>>
>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>>discover the problem, or is it still a mystery? Out side of the
>>>>>>>>>BOM, I'm only aware of XML syntax errors causing this, which I'm
>>>>>>>>>sure you've already checked.
>>>>>>>>>
>>>>>>>>>Larry
>>>>>>>>>
>>>>>>>>>Zohar wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>>>
>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>Zohar,
>>>>>>>>>>>
>>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>>reported and including the context information is skipped. The
>>>>>>>>>>>XML you show below
>>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace).
>>>>>>>>>>>The one mysterious way I am aware of to cause this problem is to
>>>>>>>>>>>be running Eclipse with a 1.4.x JRE or JDK and have a
>>>>>>>>>>>Byte-Order-Mark at the beginning of the file. The Crimson XML
>>>>>>>>>>>parser obtained from the 1.4.x JRE or JDK doesn't handle this BOM
>>>>>>>>>>>and erroneously considers it an error.
>>>>>>>>>>>
>>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>>funny characters should appear at the beginning of the file,
>>>>>>>>>>>which can be deleted. Then set the encoding back to what it was.
>>>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>>>
>>>>>>>>>>>Cheers,
>>>>>>>>>>>Larry
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>Hello,
>>>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>>>
>>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>>><Context>
>>>>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>>>>></Context>
>>>>>>>>>>>>
>>>>>>>>>>>>but in my servlet's init method, the configuration I get
>>>>>>>>>>>>contains no parameters.
>>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>>Thanks,
>>>>>>>>>>>>Zohar.
>>>>>>>>>>>>
>>>>>>>>>>
>>
Re: context.xml [message #144501 is a reply to message #144465] Wed, 19 October 2005 15:51 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
whenever I run "ServletContext context = getServletContext();" in the init
method or the doPost method) I get NPE - any idea why?

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj5n8c$ia9$1@news.eclipse.org...
> I'm not exactly sure what is meant by "because it has a slightly different
> syntax". What Tomcat would create internally for:
>
> <Parameter name="P1" value="bla"/>
>
> in your context.xml is identical to what it would create for:
>
> <context-param>
> <param-name>P1</param-name>
> <param-value>bla</param-value>
> </context-param>
>
> in a web.xml. It's two ways of doing the same thing. Perhaps that's what
> you mean by your last statement.
>
> Larry
>
> Zohar wrote:
>> So when I deploy my WAR file and indicate where its configuration file
>> is, it is equivalent to your P1 example? because it has a slightly
>> different syntax (similar to the one in context.xml).
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dj5l94$f4c$1@news.eclipse.org...
>>
>>>In web.xml you can have:
>>>
>>><web-app>
>>> <context-param>
>>> <param-name>P1</param-name>
>>> <param-value>bla</param-value>
>>> </context-param>
>>>...
>>> <servlet>
>>> <servlet-name>SomeServlet</servlet-name>
>>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>>> <init-param>
>>> <param-name>P2</param-name>
>>> <param-value>bli</param-value>
>>> </init-param>
>>> </servlet>
>>>...
>>></web-app>
>>>
>>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>>where your "config.getInitParameterNames()" will give you "P2". As a
>>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>>create the equivalent of <context-parameter> elements found in the
>>>web.xml. Thus, you can specify them without modifying the webapp's
>>>web.xml. The only problem is that your code below is trying to read
>>><init-param> info instead of <context-param> info, and as a result, is
>>>unable to see your context parameters.
>>>
>>>HTH.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>>question).
>>>>What are the options of configuring my servlet and how do I do this with
>>>>WTP? I want these parameters to be set by the servlet's deployer, not
>>>>the writer (me).
>>>>I read getServletContext's javadoc and it says that it is the same
>>>>object as the one passed to init - so what's the difference?
>>>>Thanks again,
>>>>Zohar.
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>>
>>>>
>>>>>Your parameters will appear as if your web.xml contained the equivalent
>>>>>context parameters. To read them, I believe you want:
>>>>>
>>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>>
>>>>>You are currently trying to the servlet's init parameters.
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>In my servlet I have:
>>>>>>-----------------------------8<------------------------------------------
>>>>>>public void init(ServletConfig config) throws ServletException {
>>>>>> ...
>>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>>> while(paramNames.hasMoreElements()){
>>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>>> }
>>>>>>}
>>>>>>-----------------------------8<------------------------------------------
>>>>>>
>>>>>>Nothing gets printed, and when running in debug mode I can see that
>>>>>>the enumeration is empty.
>>>>>>
>>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>To this point, I have been assuming that "in my servlet's init
>>>>>>>method, the configuration I get contains no parameters" means that
>>>>>>>the <Context> element in the server.xml under
>>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>>>the parameter elements, what does your init method look like?
>>>>>>>
>>>>>>>Larry
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>>Haven't nailed this yet...
>>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>>No logs to look at?
>>>>>>>>
>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>>discover the problem, or is it still a mystery? Out side of the
>>>>>>>>>BOM, I'm only aware of XML syntax errors causing this, which I'm
>>>>>>>>>sure you've already checked.
>>>>>>>>>
>>>>>>>>>Larry
>>>>>>>>>
>>>>>>>>>Zohar wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>>>
>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>Zohar,
>>>>>>>>>>>
>>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>>reported and including the context information is skipped. The
>>>>>>>>>>>XML you show below
>>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace).
>>>>>>>>>>>The one mysterious way I am aware of to cause this problem is to
>>>>>>>>>>>be running Eclipse with a 1.4.x JRE or JDK and have a
>>>>>>>>>>>Byte-Order-Mark at the beginning of the file. The Crimson XML
>>>>>>>>>>>parser obtained from the 1.4.x JRE or JDK doesn't handle this BOM
>>>>>>>>>>>and erroneously considers it an error.
>>>>>>>>>>>
>>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>>funny characters should appear at the beginning of the file,
>>>>>>>>>>>which can be deleted. Then set the encoding back to what it was.
>>>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>>>
>>>>>>>>>>>Cheers,
>>>>>>>>>>>Larry
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>Hello,
>>>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>>>
>>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>>><Context>
>>>>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>>>>></Context>
>>>>>>>>>>>>
>>>>>>>>>>>>but in my servlet's init method, the configuration I get
>>>>>>>>>>>>contains no parameters.
>>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>>Thanks,
>>>>>>>>>>>>Zohar.
>>>>>>>>>>>>
>>>>>>>>>>
>>
Re: context.xml [message #144520 is a reply to message #144465] Wed, 19 October 2005 16:40 Go to previous messageGo to next message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
Thank you very much for all the help. Hope to return the favor one day.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj5n8c$ia9$1@news.eclipse.org...
> I'm not exactly sure what is meant by "because it has a slightly different
> syntax". What Tomcat would create internally for:
>
> <Parameter name="P1" value="bla"/>
>
> in your context.xml is identical to what it would create for:
>
> <context-param>
> <param-name>P1</param-name>
> <param-value>bla</param-value>
> </context-param>
>
> in a web.xml. It's two ways of doing the same thing. Perhaps that's what
> you mean by your last statement.
>
> Larry
>
> Zohar wrote:
>> So when I deploy my WAR file and indicate where its configuration file
>> is, it is equivalent to your P1 example? because it has a slightly
>> different syntax (similar to the one in context.xml).
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dj5l94$f4c$1@news.eclipse.org...
>>
>>>In web.xml you can have:
>>>
>>><web-app>
>>> <context-param>
>>> <param-name>P1</param-name>
>>> <param-value>bla</param-value>
>>> </context-param>
>>>...
>>> <servlet>
>>> <servlet-name>SomeServlet</servlet-name>
>>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>>> <init-param>
>>> <param-name>P2</param-name>
>>> <param-value>bli</param-value>
>>> </init-param>
>>> </servlet>
>>>...
>>></web-app>
>>>
>>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>>where your "config.getInitParameterNames()" will give you "P2". As a
>>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>>create the equivalent of <context-parameter> elements found in the
>>>web.xml. Thus, you can specify them without modifying the webapp's
>>>web.xml. The only problem is that your code below is trying to read
>>><init-param> info instead of <context-param> info, and as a result, is
>>>unable to see your context parameters.
>>>
>>>HTH.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>>question).
>>>>What are the options of configuring my servlet and how do I do this with
>>>>WTP? I want these parameters to be set by the servlet's deployer, not
>>>>the writer (me).
>>>>I read getServletContext's javadoc and it says that it is the same
>>>>object as the one passed to init - so what's the difference?
>>>>Thanks again,
>>>>Zohar.
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>>
>>>>
>>>>>Your parameters will appear as if your web.xml contained the equivalent
>>>>>context parameters. To read them, I believe you want:
>>>>>
>>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>>
>>>>>You are currently trying to the servlet's init parameters.
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>In my servlet I have:
>>>>>>-----------------------------8<------------------------------------------
>>>>>>public void init(ServletConfig config) throws ServletException {
>>>>>> ...
>>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>>> while(paramNames.hasMoreElements()){
>>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>>> }
>>>>>>}
>>>>>>-----------------------------8<------------------------------------------
>>>>>>
>>>>>>Nothing gets printed, and when running in debug mode I can see that
>>>>>>the enumeration is empty.
>>>>>>
>>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>To this point, I have been assuming that "in my servlet's init
>>>>>>>method, the configuration I get contains no parameters" means that
>>>>>>>the <Context> element in the server.xml under
>>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>>>the parameter elements, what does your init method look like?
>>>>>>>
>>>>>>>Larry
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>>Haven't nailed this yet...
>>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>>No logs to look at?
>>>>>>>>
>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>>discover the problem, or is it still a mystery? Out side of the
>>>>>>>>>BOM, I'm only aware of XML syntax errors causing this, which I'm
>>>>>>>>>sure you've already checked.
>>>>>>>>>
>>>>>>>>>Larry
>>>>>>>>>
>>>>>>>>>Zohar wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>>>
>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>Zohar,
>>>>>>>>>>>
>>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>>reported and including the context information is skipped. The
>>>>>>>>>>>XML you show below
>>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace).
>>>>>>>>>>>The one mysterious way I am aware of to cause this problem is to
>>>>>>>>>>>be running Eclipse with a 1.4.x JRE or JDK and have a
>>>>>>>>>>>Byte-Order-Mark at the beginning of the file. The Crimson XML
>>>>>>>>>>>parser obtained from the 1.4.x JRE or JDK doesn't handle this BOM
>>>>>>>>>>>and erroneously considers it an error.
>>>>>>>>>>>
>>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>>funny characters should appear at the beginning of the file,
>>>>>>>>>>>which can be deleted. Then set the encoding back to what it was.
>>>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>>>
>>>>>>>>>>>Cheers,
>>>>>>>>>>>Larry
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>Hello,
>>>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>>>
>>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>>><Context>
>>>>>>>>>>>> <Parameter name="P1" value="bla"/>
>>>>>>>>>>>> <Parameter name="P2" value="bli"/>
>>>>>>>>>>>> <Parameter name="P3" value="blo"/>
>>>>>>>>>>>></Context>
>>>>>>>>>>>>
>>>>>>>>>>>>but in my servlet's init method, the configuration I get
>>>>>>>>>>>>contains no parameters.
>>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>>Thanks,
>>>>>>>>>>>>Zohar.
>>>>>>>>>>>>
>>>>>>>>>>
>>
Re: context.xml [message #144530 is a reply to message #144501] Wed, 19 October 2005 17:05 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
I will guess that you are using "init(ServletConfig config)" instead of
"init()" and you *aren't* calling "super.init(config)", which is
required by the servlet spec to initialize the ServletConfig field for
the servlet. Since getServletContext() uses the ServletConfig field to
get the ServletContext, you get an NPE. The simplest way to fix this is
to switch to the "init()" version of the method, which is the
recommended method to use. If you are curious, see the GenericServlet
source as to how this happens:

http://svn.apache.org/repos/asf/tomcat/servletapi/servlet2.4 -jsp2.0-tc5.x/jsr154/src/share/javax/servlet/GenericServlet. java

As for where to read about this stuff, I would imagine most any Servlet
book would cover this. If you already know a little about the
information you are looking for, you may be able to find the detail you
want in the Servlet specs themselves. The Servlet spec can be a tough
read otherwise.

Larry

Zohar wrote:
> whenever I run "ServletContext context = getServletContext();" in the init
> method or the doPost method) I get NPE - any idea why?
>
> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
> news:dj5n8c$ia9$1@news.eclipse.org...
>
>>I'm not exactly sure what is meant by "because it has a slightly different
>>syntax". What Tomcat would create internally for:
>>
>> <Parameter name="P1" value="bla"/>
>>
>>in your context.xml is identical to what it would create for:
>>
>> <context-param>
>> <param-name>P1</param-name>
>> <param-value>bla</param-value>
>> </context-param>
>>
>>in a web.xml. It's two ways of doing the same thing. Perhaps that's what
>>you mean by your last statement.
>>
>>Larry
>>
>>Zohar wrote:
>>
>>>So when I deploy my WAR file and indicate where its configuration file
>>>is, it is equivalent to your P1 example? because it has a slightly
>>>different syntax (similar to the one in context.xml).
>>>
>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>news:dj5l94$f4c$1@news.eclipse.org...
>>>
>>>
>>>>In web.xml you can have:
>>>>
>>>><web-app>
>>>> <context-param>
>>>> <param-name>P1</param-name>
>>>> <param-value>bla</param-value>
>>>> </context-param>
>>>>...
>>>> <servlet>
>>>> <servlet-name>SomeServlet</servlet-name>
>>>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>>>> <init-param>
>>>> <param-name>P2</param-name>
>>>> <param-value>bli</param-value>
>>>> </init-param>
>>>> </servlet>
>>>>...
>>>></web-app>
>>>>
>>>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>>>where your "config.getInitParameterNames()" will give you "P2". As a
>>>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>>>create the equivalent of <context-parameter> elements found in the
>>>>web.xml. Thus, you can specify them without modifying the webapp's
>>>>web.xml. The only problem is that your code below is trying to read
>>>><init-param> info instead of <context-param> info, and as a result, is
>>>>unable to see your context parameters.
>>>>
>>>>HTH.
>>>>
>>>>Larry
>>>>
>>>>Zohar wrote:
>>>>
>>>>
>>>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>>>question).
>>>>>What are the options of configuring my servlet and how do I do this with
>>>>>WTP? I want these parameters to be set by the servlet's deployer, not
>>>>>the writer (me).
>>>>>I read getServletContext's javadoc and it says that it is the same
>>>>>object as the one passed to init - so what's the difference?
>>>>>Thanks again,
>>>>>Zohar.
>>>>>
>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>>>
>>>>>
>>>>>
>>>>>>Your parameters will appear as if your web.xml contained the equivalent
>>>>>>context parameters. To read them, I believe you want:
>>>>>>
>>>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>>>
>>>>>>You are currently trying to the servlet's init parameters.
>>>>>>
>>>>>>Larry
>>>>>>
>>>>>>Zohar wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>In my servlet I have:
>>>>>>>-----------------------------8<------------------------------------------
>>>>>>>public void init(ServletConfig config) throws ServletException {
>>>>>>> ...
>>>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>>>> while(paramNames.hasMoreElements()){
>>>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>>>> String sCurrElemValue = config.getInitParameter(sCurrElemName);
>>>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>>>> }
>>>>>>>}
>>>>>>>-----------------------------8<------------------------------------------
>>>>>>>
>>>>>>>Nothing gets printed, and when running in debug mode I can see that
>>>>>>>the enumeration is empty.
>>>>>>>
>>>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>>>
>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>To this point, I have been assuming that "in my servlet's init
>>>>>>>>method, the configuration I get contains no parameters" means that
>>>>>>>>the <Context> element in the server.xml under
>>>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>>>that your servlet just doesn't see them? If the server.xml includes
>>>>>>>>the parameter elements, what does your init method look like?
>>>>>>>>
>>>>>>>>Larry
>>>>>>>>
>>>>>>>>Zohar wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>>>Haven't nailed this yet...
>>>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>>>No logs to look at?
>>>>>>>>>
>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>>>discover the problem, or is it still a mystery? Out side of the
>>>>>>>>>>BOM, I'm only aware of XML syntax errors causing this, which I'm
>>>>>>>>>>sure you've already checked.
>>>>>>>>>>
>>>>>>>>>>Larry
>>>>>>>>>>
>>>>>>>>>>Zohar wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>I checked and there is no BOM in the beginning? any other possible
>>>>>>>>>>>causes for this? can I check some logs for this somewhere?
>>>>>>>>>>>
>>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>Zohar,
>>>>>>>>>>>>
>>>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>>>reported and including the context information is skipped. The
>>>>>>>>>>>>XML you show below
>>>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace).
>>>>>>>>>>>>The one mysterious way I am aware of to cause this problem is to
>>>>>>>>>>>>be running Eclipse with a 1.4.x JRE or JDK and have a
>>>>>>>>>>>>Byte-Order-Mark at the beginning of the file. The Crimson XML
>>>>>>>>>>>>parser obtained from the 1.4.x JRE or JDK doesn't handle this BOM
>>>>>>>>>>>>and erroneously considers it an error.
>>>>>>>>>>>>
>>>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>>>funny characters should appear at the beginning of the file,
>>>>>>>>>>>>which can be deleted. Then set the encoding back to what it was.
>>>>>>>>>>>>Hopefully that is the problem.
>>>>>>>>>>>>
>>>>>>>>>>>>Cheers,
>>>>>>>>>>>>Larry
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>Hello,
>>>>>>>>>>>>>I know this has been asked a thousand times before, but I still
>>>>>>>>>>>>>seem to have problems with my servlet's context.xml .
>>>>>>>>>>>>>I created a context.xml file in my project's WebContent/META-INF
>>>>>>>>>>>>>directory. In that xml file I've put something like:
>>>>>>>>>>>>>
>>>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>>>><Context>
>>>>>>>>>>>>><Parameter name="P1" value="bla"/>
>>>>>>>>>>>>><Parameter name="P2" value="bli"/>
>>>>>>>>>>>>><Parameter name="P3" value="blo"/>
>>>>>>>>>>>>></Context>
>>>>>>>>>>>>>
>>>>>>>>>>>>>but in my servlet's init method, the configuration I get
>>>>>>>>>>>>>contains no parameters.
>>>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>>>Thanks,
>>>>>>>>>>>>>Zohar.
>>>>>>>>>>>>>
>>>>>>>>>>>
>
Re: context.xml [message #144539 is a reply to message #144530] Wed, 19 October 2005 17:21 Go to previous message
Zohar Amir is currently offline Zohar AmirFriend
Messages: 419
Registered: July 2009
Senior Member
Yes, that was it - not invoking super... :$
Thanks.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:dj5ucf$sl0$1@news.eclipse.org...
>I will guess that you are using "init(ServletConfig config)" instead of
>"init()" and you *aren't* calling "super.init(config)", which is required
>by the servlet spec to initialize the ServletConfig field for the servlet.
>Since getServletContext() uses the ServletConfig field to get the
>ServletContext, you get an NPE. The simplest way to fix this is to switch
>to the "init()" version of the method, which is the recommended method to
>use. If you are curious, see the GenericServlet source as to how this
>happens:
>
> http://svn.apache.org/repos/asf/tomcat/servletapi/servlet2.4 -jsp2.0-tc5.x/jsr154/src/share/javax/servlet/GenericServlet. java
>
> As for where to read about this stuff, I would imagine most any Servlet
> book would cover this. If you already know a little about the information
> you are looking for, you may be able to find the detail you want in the
> Servlet specs themselves. The Servlet spec can be a tough read otherwise.
>
> Larry
>
> Zohar wrote:
>> whenever I run "ServletContext context = getServletContext();" in the
>> init method or the doPost method) I get NPE - any idea why?
>>
>> "Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>> news:dj5n8c$ia9$1@news.eclipse.org...
>>
>>>I'm not exactly sure what is meant by "because it has a slightly
>>>different syntax". What Tomcat would create internally for:
>>>
>>> <Parameter name="P1" value="bla"/>
>>>
>>>in your context.xml is identical to what it would create for:
>>>
>>> <context-param>
>>> <param-name>P1</param-name>
>>> <param-value>bla</param-value>
>>> </context-param>
>>>
>>>in a web.xml. It's two ways of doing the same thing. Perhaps that's
>>>what you mean by your last statement.
>>>
>>>Larry
>>>
>>>Zohar wrote:
>>>
>>>>So when I deploy my WAR file and indicate where its configuration file
>>>>is, it is equivalent to your P1 example? because it has a slightly
>>>>different syntax (similar to the one in context.xml).
>>>>
>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>news:dj5l94$f4c$1@news.eclipse.org...
>>>>
>>>>
>>>>>In web.xml you can have:
>>>>>
>>>>><web-app>
>>>>> <context-param>
>>>>> <param-name>P1</param-name>
>>>>> <param-value>bla</param-value>
>>>>> </context-param>
>>>>>...
>>>>> <servlet>
>>>>> <servlet-name>SomeServlet</servlet-name>
>>>>> <servlet-class>some.pkg.SomeServlet</servlet-class>
>>>>> <init-param>
>>>>> <param-name>P2</param-name>
>>>>> <param-value>bli</param-value>
>>>>> </init-param>
>>>>> </servlet>
>>>>>...
>>>>></web-app>
>>>>>
>>>>>Using "getServletContext().getInitParameterNames()" will give you "P1",
>>>>>where your "config.getInitParameterNames()" will give you "P2". As a
>>>>>bonus feature of Tomcat, your <Parameter> elements in the context.xml
>>>>>create the equivalent of <context-parameter> elements found in the
>>>>>web.xml. Thus, you can specify them without modifying the webapp's
>>>>>web.xml. The only problem is that your code below is trying to read
>>>>><init-param> info instead of <context-param> info, and as a result, is
>>>>>unable to see your context parameters.
>>>>>
>>>>>HTH.
>>>>>
>>>>>Larry
>>>>>
>>>>>Zohar wrote:
>>>>>
>>>>>
>>>>>>I'm a bit confused then (this may be a servlet / tomcat general
>>>>>>question).
>>>>>>What are the options of configuring my servlet and how do I do this
>>>>>>with WTP? I want these parameters to be set by the servlet's deployer,
>>>>>>not the writer (me).
>>>>>>I read getServletContext's javadoc and it says that it is the same
>>>>>>object as the one passed to init - so what's the difference?
>>>>>>Thanks again,
>>>>>>Zohar.
>>>>>>
>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>news:dj0c6k$k46$1@news.eclipse.org...
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Your parameters will appear as if your web.xml contained the
>>>>>>>equivalent context parameters. To read them, I believe you want:
>>>>>>>
>>>>>>>Enumeration paramNames = getServletContext().getInitParameterNames();
>>>>>>>
>>>>>>>You are currently trying to the servlet's init parameters.
>>>>>>>
>>>>>>>Larry
>>>>>>>
>>>>>>>Zohar wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>In my servlet I have:
>>>>>>>>-----------------------------8<------------------------------------------
>>>>>>>>public void init(ServletConfig config) throws ServletException {
>>>>>>>> ...
>>>>>>>> Enumeration paramNames = config.getInitParameterNames();
>>>>>>>> while(paramNames.hasMoreElements()){
>>>>>>>> String sCurrElemName = (String) paramNames.nextElement();
>>>>>>>> String sCurrElemValue =
>>>>>>>> config.getInitParameter(sCurrElemName);
>>>>>>>> System.out.println(sCurrElemName+"="+sCurrElemValue);
>>>>>>>> }
>>>>>>>>}
>>>>>>>>-----------------------------8<------------------------------------------
>>>>>>>>
>>>>>>>>Nothing gets printed, and when running in debug mode I can see that
>>>>>>>>the enumeration is empty.
>>>>>>>>
>>>>>>>>I deleted the project and recreated it, but it didn't help.
>>>>>>>>
>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>news:digta3$2fo$1@news.eclipse.org...
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>To this point, I have been assuming that "in my servlet's init
>>>>>>>>>method, the configuration I get contains no parameters" means that
>>>>>>>>>the <Context> element in the server.xml under
>>>>>>>>>".metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf " doesn't
>>>>>>>>>include the <Parameter> child elements. Is this the case, or is it
>>>>>>>>>that your servlet just doesn't see them? If the server.xml
>>>>>>>>>includes the parameter elements, what does your init method look
>>>>>>>>>like?
>>>>>>>>>
>>>>>>>>>Larry
>>>>>>>>>
>>>>>>>>>Zohar wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>Thanks for the reply (hope you had a nice vacation).
>>>>>>>>>>Haven't nailed this yet...
>>>>>>>>>>The file is valid (used XML Spy to check it).
>>>>>>>>>>No logs to look at?
>>>>>>>>>>
>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>news:digdcj$8kp$1@news.eclipse.org...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>Sorry for the delayed response. I was away on vacation. Did you
>>>>>>>>>>>discover the problem, or is it still a mystery? Out side of the
>>>>>>>>>>>BOM, I'm only aware of XML syntax errors causing this, which I'm
>>>>>>>>>>>sure you've already checked.
>>>>>>>>>>>
>>>>>>>>>>>Larry
>>>>>>>>>>>
>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>I checked and there is no BOM in the beginning? any other
>>>>>>>>>>>>possible causes for this? can I check some logs for this
>>>>>>>>>>>>somewhere?
>>>>>>>>>>>>
>>>>>>>>>>>>"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
>>>>>>>>>>>>news:dhh145$2m6$1@news.eclipse.org...
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>Zohar,
>>>>>>>>>>>>>
>>>>>>>>>>>>>On the todo list is to improve the error handing if there is a
>>>>>>>>>>>>>problem reading the context.xml. Currently, there is no error
>>>>>>>>>>>>>reported and including the context information is skipped. The
>>>>>>>>>>>>>XML you show below
>>>>>>>>>>>>>looks fine (works copy & pasted in a webapp in my workspace).
>>>>>>>>>>>>>The one mysterious way I am aware of to cause this problem is
>>>>>>>>>>>>>to be running Eclipse with a 1.4.x JRE or JDK and have a
>>>>>>>>>>>>>Byte-Order-Mark at the beginning of the file. The Crimson XML
>>>>>>>>>>>>>parser obtained from the 1.4.x JRE or JDK doesn't handle this
>>>>>>>>>>>>>BOM and erroneously considers it an error.
>>>>>>>>>>>>>
>>>>>>>>>>>>>If this is the case, you can open the context.xml with the Text
>>>>>>>>>>>>>Editor. Set the encoding to be US-ASCII or ISO-8859-1 and three
>>>>>>>>>>>>>funny characters should appear at the beginning of the file,
>>>>>>>>>>>>>which can be deleted. Then set the encoding back to what it
>>>>>>>>>>>>>was. Hopefully that is the problem.
>>>>>>>>>>>>>
>>>>>>>>>>>>>Cheers,
>>>>>>>>>>>>>Larry
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>Zohar wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>>Hello,
>>>>>>>>>>>>>>I know this has been asked a thousand times before, but I
>>>>>>>>>>>>>>still seem to have problems with my servlet's context.xml .
>>>>>>>>>>>>>>I created a context.xml file in my project's
>>>>>>>>>>>>>>WebContent/META-INF directory. In that xml file I've put
>>>>>>>>>>>>>>something like:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>><?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>>>>><Context>
>>>>>>>>>>>>>><Parameter name="P1" value="bla"/>
>>>>>>>>>>>>>><Parameter name="P2" value="bli"/>
>>>>>>>>>>>>>><Parameter name="P3" value="blo"/>
>>>>>>>>>>>>>></Context>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>but in my servlet's init method, the configuration I get
>>>>>>>>>>>>>>contains no parameters.
>>>>>>>>>>>>>>I've tried do "publish" manually, deploy/undeploy the module.
>>>>>>>>>>>>>>I'm using tomcat 5.5 on Win XP with eclipse 3.1 and WTP 0.7 .
>>>>>>>>>>>>>>What may be the cause of this?
>>>>>>>>>>>>>>Thanks,
>>>>>>>>>>>>>>Zohar.
>>>>>>>>>>>>>>
>>>>>>>>>>>>
>>
Previous Topic:WTP 0.7.1 translation packs are available
Next Topic:TCP/IP Monitor
Goto Forum:
  


Current Time: Sat Apr 27 05:08:45 GMT 2024

Powered by FUDForum. Page generated in 0.04984 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top