Servlet configuration

Inside servlet container, the object of  javax.servlet.ServletConfig is used to represents the servlet configurations. The configuration information conatains the servlet ‘s initialization parameters, the name of the servlet and servlet contaxt which gives the information about container. The servletinitialization parameter and the servlet name can be spacified in the deployment descriptor (web.xml).

For example
            <param-value>bye user</param-value>

Following example will retrieves parameter from init-param tag of the servlet
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet{
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
        PrintWriter pw=res.getWriter();
        ServletConfig config=getServletConfig();
        String s=config.getInitParameter("p1");

No comments:

Popular Posts