Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

can anybody help me please(problem with init parameters)

843841Dec 27 2004 — edited Dec 28 2004
Dear Friends,

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the
"License");
you may not use this file except in compliance with
the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in
writing, software
distributed under the License is distributed on an
"AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.
See the License for the specific language governing
permissions and
limitations under the License.
-->

<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-mapping>

<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>

<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>

<!-- JSPC servlet mappings end -->

</web-app>


my servlet code looks like this
package com.jspbook;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class InternationalizedHelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse 

response) throws IOException, ServletException {

	response.setContentType("text/html");

	PrintWriter out = response.getWriter();

	String greeting;

	greeting = (String) 

getServletConfig().getInitParameter("balbeer");
	
	if(greeting != null) {

	System.out.println("lopaliki vachav");
	
	out.println("<html>");
	out.println("<head>");
	out.println("<title>Shabbu Bhai</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>Shabbu Bhai</title>");
	out.println("</head>");
	out.println("<body>");
	out.println("<h1>Emiledura Dunna</h1>");
	out.println("</body>");
	out.println("</html>");
	
	
	}	
	
     }
  }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2005
Added on Dec 27 2004
8 comments
349 views