Skip to main content

Featured

Game Development Tutorials In Android

Game Development Tutorials In Android Hi Guys,                 We are shortly started Game Development Tutorials in Android Studio. So everyone supports me and share this blogs to your friends. Guys, At this time everyone is freely available to source code and we are provide a video for step by step game developments. you are learn free and feel free to support us. Guys, if you have any question to me, so feel free to comment us. I will try to answer all the question as long as possible.                                                     Thank's                                                                          ...

Example of ServletContext to get the initialization parameter

Example of ServletContext to get the initialization parameter

 we are getting the initialization parameter from the web.xml file and printing the value of the initialization parameter. Notice that the object of ServletContext represents the application scope. So if we change the value of the parameter from the web.xml file, all the servlet classes will get the changed value. So we don't need to modify the servlet. So it is better to have the common information for most of the servlets in the web.xml file by context-param element. Let's see the simple example:

DemoServlet.java
1.     import java.io.*;  
2.     import javax.servlet.*;  
3.     import javax.servlet.http.*;  
4.       
5.       
6.     public class DemoServlet extends HttpServlet{  
7.     public void doGet(HttpServletRequest req,HttpServletResponse res)  
8.     throws ServletException,IOException  
9.     {  
10.   res.setContentType("text/html");  
11.   PrintWriter pw=res.getWriter();  
12.     
13.   //creating ServletContext object  
14.   ServletContext context=getServletContext();  
15.     
16.   //Getting the value of the initialization parameter and printing it  
17.   String driverName=context.getInitParameter("dname");  
18.   pw.println("driver name is="+driverName);  
19.     
20.   pw.close();  
21.     
22.   }}  
web.xml
1.     <web-app>  
2.       
3.     <servlet>  
4.     <servlet-name>sonoojaiswal</servlet-name>  
5.     <servlet-class>DemoServlet</servlet-class>  
6.     </servlet>  
7.       
8.     <context-param>  
9.     <param-name>dname</param-name>  
10.   <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>  
11.   </context-param>  
12.     
13.   <servlet-mapping>  
14.   <servlet-name>sonoojaiswal</servlet-name>  
15.   <url-pattern>/context</url-pattern>  
16.   </servlet-mapping>  
17.     
18.   </web-app>  

If this information is important to you , and you want to , I will continue writing some more details of programming language, so click on the advertising, available on this page. This is motivate me for writing some more blogs.

Comments