繁体   English   中英

从Java的xml属性文件中获取价值并在jsp页面上使用

[英]Get value from xml properties file in Java and using on jsp page

我有一个属性xml文件,例如:

<properties>
  <entry key="message.first">Hello</entry>
  <entry key="message.second">Hi</entry>
</properties>

我想从属性文件中获取值,并检查jsp页面上是否存在值。

例:

if(message.first != null) {
     action
}

我现在不怎么从属性文件中获取值并在jsp页面的if语句中使用。

用于加载properties.xml文件:

    Properties properties = new Properties();
    properties.loadFromXML(new FileInputStream("props.xml")); //path of XML file
    String  firstname = properties.getProperty("firstname");

用于将其发送到JSP页面 :-

    request.setAttribute("firstname ", firstname )
    request.getRequestDispatcher("NEWPAGE.jsp").forward(request, response);

暂无
暂无

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

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