Hi,
I was trying th example of using the initialization parameters from marty hall's "coreservlets".I have changes my web.xml file accordingly but am not able to access it through the servlet.ie when i run the
servlet from the browser, it doest pick the settings in web.xmll, but uses the default value given in servlet file. i placed my files under a folder called sangi and this is under jakarta../webapps/examples/web-inf/classes
code is as follows-----
package sangi;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class showmsg extends HttpServlet{
private
String message;
private String defaultMessage="No message.";
private int repeats =1;
public void init(ServletConfig config)
throws ServletException
{super.init(config);
message=config.getInitParamete("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 show message servlet";
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n"+
"<H1 ALIGN=CENTER>" + title+"</H1>");
for(int i=0;i<5;i++)
{
out.println(message + "<BR>");
}
out.println("</BODY></HTML>");
}
}
and i added the following to the xml file
<servlet>
<servlet-name>showmsg</servlet-name>
<servlet-class>sangi.showmsg</servlet-class>
<init-param>
<param-name>
message
</param-name>
<param-value>
sangishan
</param-value>
</init-param>
<init-param>
<param-name>
repeats
</param-name>
<param-value>
5
</param-value>
</init-param>
</servlet>
<servlet-mapping> <servlet-name>showmsg</servlet-name>
<url-pattern>/showmsg</url-pattern> </servlet-mapping>