Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
    Bookmark Topic Watch Topic
  • Mark post as helpful
  • send pies
  • Report post to moderator
How to access servlet init parameters using EL?

You cannot use the following syntax to access servlet init parameters:

You cannot get Servlet init parameters using this technique. The getInitParameter(java.lang.String name) does not fit in this case, because it requires some arguments.

According to the JavaBean spec, the property has getter & setter methods in the form

Now consider the pageContext as bean Object. The PageContext class has methods like getServletConfig(), getRequest(), getSession() etc. You can access these like pageContext.pageConfig, pageContext.request etc in EL.

ServletContext object has a couple of methods like getMajorVersion(), getMinorVersion() with no args. so we can access these methods treating it as properties to sevletContext bean as pageContext.servletContext.majorVersion and pageContext.servletContext.minorVersion.

If you want to access Servlet init parameters using EL, then it is better to create a Map of the init parameters for the servlet and place it in the request as a scoped variable -- let's say initParameters. You would then be able to obtain any param by name with ${}.


We can access context init parameters with ${}

    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!