如何使用weblogic 10.3.x动态传递web.xml中的参数?
我试图在启动 weblogic 服务器时使用 -D 表示法将 web.xml 中配置的变量的 JVM 参数传递为上下文参数。我已经使用 Tomcat 7 尝试过相同的配置,它按预期工作,但它在 weblogic 服务器 10.3.3 中不起作用。有什么线索吗?
web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>testeParWebXml</display-name>
<context-param>
<description>Habilita ou desabilita a configuração de debug do Facelets! Página de debug do Seam.</description>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>${habilitar.debug}</param-value>
</context-param>
<welcome-file-list>
然后,在启动 jvm 时,我使用以下方法传递参数:
-Dhabilitar.debug=true
我构建了一个 Servlet 来测试:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
String valorParametro = getServletContext().getInitParameter("facelets.DEVELOPMENT");
pw.write("Param value from web.xml ==>> " + valorParametro);
}
正如我提到的,如果我将 -Dhabilitar.debug 标志中的值更改为 false 或 true,则使用 Tomcat它正确打印 servlet 中的值。
Param value from web.xml ==>> true
在 weblogic 中,我得到如下输出:
Param value from web.xml ==>> ${habilitar.debug}
正如所注意到的,weblogic 不会解析 web.xml 中设置的变量的值。
是否可以使其在 weblogic 10.3.3 中正常工作?
I am trying to pass a JVM parameter for a variable configured in web.xml as a context-parameter using a -D notation when starting weblogic server. I have already tried this same configuration using Tomcat 7 and it works as expected, but it DOES NOT work in weblogic server 10.3.3. Any clues?
web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>testeParWebXml</display-name>
<context-param>
<description>Habilita ou desabilita a configuração de debug do Facelets! Página de debug do Seam.</description>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>${habilitar.debug}</param-value>
</context-param>
<welcome-file-list>
Then when starting the jvm I pass the parameter using:
-Dhabilitar.debug=true
And I built a Servlet to test:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
String valorParametro = getServletContext().getInitParameter("facelets.DEVELOPMENT");
pw.write("Param value from web.xml ==>> " + valorParametro);
}
As I mentioned using Tomcat if I change the value to false or true in the -Dhabilitar.debug flag it correctly prints the value in the servlet.
Param value from web.xml ==>> true
In weblogic I get the output like:
Param value from web.xml ==>> ${habilitar.debug}
As noticed weblogic DOES NOT parse the value of the variable set in web.xml.
Is it possible to make this work properly in weblogic 10.3.3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来不同容器之间的行为不一致。恕我直言,你不应该这样做。我一直使用(并且总是看到人们使用)包含默认值(而不是参数化值)的 web.xml 。
请参阅这些附加资源(包括一些不太优雅但可以解决您的问题的方法):
Looks like there is not a consistent behavior across different containers. IMHO you should not do it that way. I have always used (and have always seen people using) web.xml containing default values (rather than parameterized values) for stuff.
Please see these additional resources (including some not-so-elegant but working approaches to your problem):
第一次尝试:
我认为过滤 web.xml 等关键文件并不是一个好的做法。但是,您可以使用 ant 或 maven 来做到这一点。
===
第二次尝试:
好的,如果必须使用相同的包,我更愿意更改 doPost 方法。可以不将值传递给那里,而是传递键并通过那里的 System.getProperty 方法进行设置。设置默认值(例如开发环境)也是有意义的。
First attempt:
I believe that filtering crucial files such as web.xml is not a good practice. However you can use ant or maven to do that.
===
Second attempt:
Ok If identical packages are mandatory, I would prefer changing doPost method. Instead of passing the value to there, it could be passed key and set by System.getProperty method at there. And also setting a default value such as development environment makes sense.