I have written a simple servlet which reads a init parameter from the web.xml file and displays on the browser. I'm a beginner and trying to learn simple servlets, I have reached where I can read some init params from the web.xml file and displays on the browser, but all the simple servlets are working without any hassle, but reading init parameter returns null in the servlet, because I triend to print that on to the console, but it returns null, please help me, awaiting a reply, regards Raasi
web.xml looks like this [code] <?xml version="1.0" encoding="ISO-8859-1"?> <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"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- JSPC servlet mappings start --> <servlet> <servlet-name>org.apache.jsp.index_jsp</servlet-name> <servlet-class>org.apache.jsp.index_jsp</servlet-class> </servlet> <servlet> <servlet-name>InternationalizedHelloWorld</servlet-name> <servlet-class>com.jspbook.InternationalizedHelloWorld</servlet-class> <init-param> <param-name>greeting</param-name> <param-value>Kisahairetu</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>InternationalizedHelloWorld</servlet-name> <url-pattern>/InternationalizedHelloWorld</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>org.apache.jsp.index_jsp</servlet-name> <url-pattern>/index.jsp</url-pattern> </servlet-mapping> <!-- JSPC servlet mappings end --> </web-app> [/code] [code] and here is my servlet looks like this package com.jspbook; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class InternationalizedHelloWorld extends HttpServlet { private String greeting; public void init(ServletConfig config) throws ServletException { // Always call super.init super.init(config); greeting = config.getInitParameter("greeting"); if (greeting == null) { greeting = "returns null"; } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // String greeting; // greeting = getInitParameter("greeting"); // greeting = getServletContext().getInitParameter("greeting"); if(greeting != null) { System.out.println("lopaliki vachav"); out.println("<html>"); out.println("<head>"); out.println("<title>Greeting Servlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>" + greeting + "</h1>"); out.println("</body>"); out.println("</html>"); } else { System.out.println("bayate unnav"); out.println("<html>"); out.println("<head>"); out.println("<title>Greeting Servlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Emiledura Dunna</h1>"); out.println("</body>"); out.println("</html>"); } } } [/code] __________________________________ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://my.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
