JSF 2 – How to Get a context-param Value from web.xml

Using context-param in web.xml we can declare some constant values which will be used by JSF 2 Application.
In this tutorial we are going to show you how to get web application context parameter values in JSF 2 application by using the following two ways-

-Getting the value from inside a backing bean
-Getting the value directly inside a Facelets page using JSF EL.

Declare the context parameter value inside web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet-name>Faces Servlet</servlet-name>
    <!-- declaring static value with a param name using context-param -->
    <!-- This value is going to be read in our sample application.-->
        <param-value>Static param value</param-value>
        <servlet-name>Faces Servlet</servlet-name>


<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        <title>Reading context parameter example</title>
            <h:panelGrid id="panel1" columns="2" border="1" 
                         cellpadding="5" cellspacing="1">
                <f:facet name="header">
                    <h:outputText value="Reading context parameter example"/>
                <h:outputLabel>Read the context parameter through bean</h:outputLabel>
                <h:outputText value="#{paramBean.contextParameter}"/>
                <h:outputLabel>Read the context parameter with the EL</h:outputLabel>
                <h:outputText value="#{initParam['myParamName']}"/>


package com.example.javaknowledge;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

public class ParamBean implements Serializable {

    private static final long serialVersionUID = 1L;

     * This method returns the myParamName parameter value.
     * @return
    public String getContextParameter() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        String myConstantValue =
        return myConstantValue;

Result Page:



Hello! I am Md. Abdul Bari; founder and admin of javaknowledge; currently providing training as a J2EE faculty in The Computers Ltd. Dhaka, Bangladesh under an IT Scholarship project provided by IDB-BISEW. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

More Posts - Website

Follow Me:
TwitterFacebookGoogle Plus

13,787` Total Views

One comment

  • Hello sir, I’m Guruputra presently working in one IT company, where the project leader and other experienced persons are not ready tell these concepts at all, really i was struggled much for this and i start to learn by myself, while searching things in internet i got this web site. Now i’m learning all the techniques of jsf that might be CRUD or EL and ext.

    Really i’m all ways thanks full to you.

    Guruputra K M

Leave a Reply

Your email address will not be published. Required fields are marked *

four − 3 =