aspose file tools*
The moose likes Struts and the fly likes TC4-TC5.5 with context-param Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "TC4-TC5.5 with context-param" Watch "TC4-TC5.5 with context-param" New topic
Author

TC4-TC5.5 with context-param

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
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>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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?


Merrill
Consultant, Sima Solutions
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Aug 27, 2005
Posts: 156
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

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TC4-TC5.5 with context-param