简体   繁体   English

来自jsp中web.xml的Java Web应用程序全局参数

[英]Java web application global parameters from web.xml in jsp

How do I retreive a parameter/variable htmlRootPath from the web.xml and inject it into my header jsp template (see below)? 如何从web.xml中检索参数/变量htmlRootPath并将其注入我的头jsp模板(见下文)? 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. 目前我使用的是initialize.jsp包含文件并且它可以工作,但是想知道我是否可以在web.xml文件中使用它。 I have read about using web.xml in a Servlet but how can I do it in a jsp. 我已经阅读过在Servlet中使用web.xml但是如何在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. 编辑:我想传递htmlRootPath的原因是因为这是我用于我开发的每个应用程序的头模板。 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. 我们的Configuration Management组控制生产中的源代码(jsp,java),但不控制HTML。
So my webapp folder is off limits by me in production. 所以我的webapp文件夹在生产中不受限制。 But what if I want to modify my CSS file? 但是,如果我想修改我的CSS文件怎么办? I didn't show this above, but I use <c:import for a navaigation menu located outside the web app folder. 我没有在上面显示,但是我使用<c:import来查找位于web app文件夹之外的navaigation菜单。 That way I can add a new link to my navigation without going through the CM Change Request Process (paper work and signatures! yuk) 这样,我可以添加一个新的链接到我的导航,而无需通过CM变更请求流程(文书工作和签名!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. 由于此标头是我用于许多不同应用程序的模板文本,因此我只需要编辑每个特定Web应用程序ONCE的此非配置控制文件夹的路径。

Context-wide initialization parameters <context-param> are as a Map available by ${initParam} . 上下文范围的初始化参数<context-param>${initParam}可用的Map

So: 所以:

${initParam.htmlRootPath}

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM