Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
 
friki data migration
Ranch Hand
Posts: 772
  • 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 ${requestScope.initParameters.name}.

NOTE:

We can access context init parameters with ${initParam.name}




ScwcdFaq
 
    Bookmark Topic Watch Topic
  • New Topic