Skip to main content

Posts

Showing posts from April, 2021

getInitParameterName() method in ServletConfig Interface [ Servlet ]

To get the name of the servlet which we created for our project you just need to create object of " ServletConfig " Interface. By writing these simple lines you can create an object of ServletConfig Interface and find the servlet name as well : ServletConfig ob = getServletConfig(); String servlet_name = ob.getServletName(); Now simply print " servlet_name " variable and also remember this if it's not working try to convert this variable in string type. Hope your error will remove. Output as:

getInitParameterNames() method in ServletConfig [ Servlet ]

ServletConfig in Servlet

ServletConfig is just only a object created by container itself.When servlet is loaded on the server at that time container make the servletconfig object by which you can simply do any required change in Web.xml file directly without disturbing any specific servlet. All the configurations can directly change by manipulating in a web.xml file there is no need to modifications in relevant servlet class file. ServletConfig is a interface actually who's object is created by container. by using that object we can do various changes in a servlet files without even touching that servlet file. There are 4 methods available in this interface as: 1 > getInitParameter(); 2 > getInitParameterNames(); 3 > getServletName(); 4 > getServletContext();

Create Servlet in a Eclipse

How to do it ? You just need to click on the create new file and select automatically suggested servlet. After click on this you find a dialog box is open in your system where you need to give your desired name of your servlet class. Click on next and select your method doGet & doPost whatever you're using in your html/jsp form. Now your servlet class is created successfully. New File-->Servlet-->select methods (doGet/doPost)-->Next/Finish.