?
Solved

not able to access parameters  stored in web.xml from a servlet

Posted on 2006-04-30
6
Medium Priority
?
240 Views
Last Modified: 2013-11-24
I am using tomcat 5.0  I AM NOT ABLE TO READ THE PARAMETERS in web.xml.
 the code is given below

ShowMessage.java
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowMessage extends HttpServlet {
private String message;
private String defaultMessage = "No message";
private int repeats = 1;
public void init(ServletConfig config)
throws ServletException {
// Always call super.init
super.init(config);
message = config.getInitParameter("message");
if (message == null) {
message = defaultMessage;
}
try {
String repeatString = config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
} catch(NumberFormatException nfe) {
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "The ShowMessage Servlet";
out.println(ServerUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>");
for(int i=0; i<repeats; i++) {
      out.println(message + "<BR>");
      }
      out.println("</BODY></HTML>");
      }
      }

The Web.xml file
<web-app >
                               <servlet>
            
            <servlet-name>ShowMsg</servlet-name>
            <servlet-class>coreservlets.ShowMessage</servlet-class>
            <init-param>
                  <param-name>message</param-name>
                  <param-value>Shibboleth</param-value>
            </init-param>
            <init-param>
                  <param-name>repeats</param-name>
                  <param-value>5</param-value>
            </init-param>
      </servlet>
</web-app>

The output I get is
The ShowMessage Servlet
No message
 
Please Help
0
Comment
Question by:cakurien
6 Comments
 
LVL 3

Expert Comment

by:arun_kuttz
ID: 16575953
check if the deployed servlet has the right version of the web.xml..
there does not seem to be any reason y this shouldn work..
0
 
LVL 3

Expert Comment

by:arun_kuttz
ID: 16575963
also check which version of the servlet API is supported by tomcat 5.0, and ensure the right DTD is reffered to in the web.xml
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16576072
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16576405
BTW, does: >> repeats = Integer.parseInt(repeatString);

throw any exceptions? Is repeatString also not coming properly?
0
 

Author Comment

by:cakurien
ID: 16584398
I got the ans I had to add the package name.class in <servlet-mapping> tag
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 1500 total points
ID: 16584851
You already had coreservlets.ShowMessage in the <servlet-class> so the package-name was there?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question