簡體   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