Java web application global parameters from web.xml in jsp

java, web-applications, web.xml

Solution

Context-wide initialization parameters `<context-param>` are as a `Map` available by `${initParam}`.

So:

${initParam.htmlRootPath}

See also:

- Java EE 5 tutorial - Implicit objects in EL

Problem

How do I retreive a parameter/variable `htmlRootPath` from the web.xml and inject it into my header jsp template (see below)? Currently I use an `initialize.jsp` include file and it works, but would like to learn if I could do it with something in the web.xml file. I have read about using web.xml in a Servlet but how can I do it in a jsp. ---- This is how I do it now. ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ include file="inc_taglibs.jsp" %> <%@ include file="inc_initialize.jsp" %> <html> <head> <title>D463 - Solid Mechanics - [<c:out value="${dbTable.strTableTitle}" />] <c:out value="${param.pageTitle}" /></title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="<c:out value="${htmlRootPath}"/>/css/styleScreen.css" media="screen" /> <link rel="stylesheet" type="text/css" href="<c:out value="${htmlRootPath}"/>/css/stylePrint.css" media="print" /> <link rel="stylesheet" type="text/css" href="<c:out value="${htmlRootPath}"/>/css/cssmenu.css" media="all"/> <link rel="stylesheet" type="text/css" href="<c:out value="${htmlRootPath}"/>/css/calendarPOP.css" media="all"/> <script type='text/javascript' src='<c:out value="${htmlRootPath}"/>/javascript/calendar_popup.js'></script> <script type='text/javascript' src='<c:out value="${htmlRootPath}"/>/javascript/collapse.js'></script> <script type='text/javascript' src='<c:out value="${htmlRootPath}"/>/javascript/sorttable.js'></script> <script type='text/javascript' src='<c:out value="${htmlRootPath}"/>/javascript/window_popup.js'></script> <script type='text/javascript' src='<c:out value="${htmlRootPath}"/>/javascript/switchLogin.js'></script> </head> ``` EDIT: The reason why I want to pass in the htmlRootPath is because this is a header template that I use for every application I develop. It gives a consistent feel to my applications used by co-workers as to company logo, navigation, layout, etc... Our Configuration Management group controls source code (jsp, java) that is in production, but not HTML. So my webapp folder is off limits by me in production. But what if I want to modify my CSS file? I didn't show this above, but I use `<c:import` for a navaigation menu located outside the web app folder. That way I can add a new link to my navigation without going through the CM Change Request Process (paper work and signatures! yuk) Since this header is template text that I use for many different applications, I'd rather only have to edit the path to this non-configuration-controlled folder for each particular web app ONCE.

Original source