How do I read servlet init parameter?
Category: javax.servlet, viewed: 972 time(s).
When configuring a servlet in the web.xml file we can define some init parameter in the servlet configuration section. This init parameter can be used for instance where a configuration file of our application is stored. This simple servlet show how to obtains these parameters value.
package org.kodejava.example.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class InitParameterServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // // Get application configuration path // String configPath = getInitParameter("configPath"); System.out.println("Configuration Path: " + configPath); } } |
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I get servlet request header information?
- How do I get servlet request URL information?
- How do I read servlet context initilization parameters?
- How do I know session last access time?
- How do I get a notification when session attribute was changed?
- How do I capture session creation and removal events?
- How do I invalidate user's session?
- How do I get client IP and hostname in Servlet?
- How do I set the maximum age of a cookie?
- How do I send a response status in servlet?