• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TC4-TC5.5 with context-param

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
The following works in an action hosted under TC4 and fail under TC5.5x:
totalSamples = Integer.parseInt(servlet.getInitParameter("totalSamples"));

What is the necessary syntax to make this intent work under TC5.5x? What is the correct way to do it under TC5.5x? tia.

web.xml abbrev.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<context-param>
<param-name>mp3-dir</param-name>
<param-value>F:\Projects\OP</param-value>
</context-param>
<context-param>
<param-name>totalSamples</param-name>
<param-value>11</param-value>
</context-param>
<jsp-config>
</jsp-config>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the variable "servlet" in this code is referring to the ServletContext, it should work in either version of Tomcat. What's the message you're getting when it fails?
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
If the variable "servlet" in this code is referring to the ServletContext, it should work in either version of Tomcat. What's the message you're getting when it fails?



Hi Merrill
Thanks. There is no message other than it set totalSamples to null and I get a numberFormatException. What is so odd is the exact same code and segement of the web.xml works fine in TC4. I know that is not possible, but barring some typo or syntax error that is what I am getting. Further ideas? tia.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you 100% sure that the variable "servlet" is referring to the ServletContext, and not to a servlet? They both have getInitParameter methods, so it would be easy to confuse the two. The fact that the variable is named "servlet" instead of "servletContext" makes me wonder.

Could you show the code that populates the "servlet" variable?
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Merrill Higginson:
Are you 100% sure that the variable "servlet" is referring to the ServletContext, and not to a servlet? They both have getInitParameter methods, so it would be easy to confuse the two. The fact that the variable is named "servlet" instead of "servletContext" makes me wonder.

Could you show the code that populates the "servlet" variable?



Hi Merrill
I am just using the object as defined in the Action class. How should I be creating the object?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The object you want is not the servlet (type ActionServlet extending HTTPServlet), but the servletContext (type ServletContext). In an Action Class, here's how you would get it:

ServletContext servletContext = servlet.getServletContext();

Call the getInitParameter method on this object and your code should work.
 
reply
    Bookmark Topic Watch Topic
  • New Topic