java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4096
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to write a servlet that works with initilization parameters E-mail
User Rating: / 5
PoorBest 

This J2EE example demonstrates a Java Servlet that retrieves some initialization parameters through getInitParameter() method. This method returns the value of the named init parameter or null if it does not exist. The return value is always a single String. It is up to the java servlet to interpret the value. This helps the developer to pass values dynamically instead of hard coding the values, which would then require recompiling.

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

public class ServletInitParameters extends HttpServlet {
  private String Hello;

  public void init(ServletConfig configthrows ServletException {
  Hello = getInitParameter("greeting");

  /*
  Initialization information is passed to the servlet via 
  the ServletConfig parameter of the init() method. 
  */
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {

  PrintWriter out = response.getWriter();

  out.println("<title>" + Hello + "</title>");
  out.println("<h1>" + Hello + "</h1>");
  }
  
  public void destroy()
  {
    // nothing to do
  }
}


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.