A Servlet That Uses 
Initialization Parameters
public class ShowMessage extends HttpServlet {
private String message;
private String defaultMessage = "No message.";
private int repeats = 1;
public void init() throws ServletException {
ServletConfig config = getServletConfig();
message = config.getInitParameter("message");
if (message == null) {
message = defaultMessage;
}
try {
String repeatString =
config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
} catch(NumberFormatException nfe) {}
}
21
Servlets
www.corewebprogramming.com
ShowMessage Servlet 
(Continued)
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(ServletUtilities.headWithTitle(title)+
"\n" +
"

" + title + "

");
for(int i=0; i<
repeats
; i++) {
out.println(
message
+ "
");
}
out.println("");
}
}
22
Servlets
www.corewebprogramming.com
11




  

Home

About Services Network Support FAQ Order Contact
 

Servlet Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved