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

时间:2015-07-20 19:33:21

标签: java jsp properties

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

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

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

示例:

    $keyword = "Led Zeppelin";
    $words = explode(" ",$keyword);

    $keyword_parts = '';
    foreach ($words as $w) {
        $keyword_parts .= "+" . $w ." ";
    }
    $keyword_parts = substr($keyword_parts,0,-1);
    $query = "SELECT
              *,
              MATCH (column1,column2) AGAINST ('" . $keyword . "') as score
              FROM table
              WHERE MATCH (column1,column2) AGAINST ('" . $keyword_parts . "' IN BOOLEAN MODE)
              ORDER BY score DESC";

我现在不知道如何从属性文件获取值并在jsp页面上使用if statment。

1 个答案:

答案 0 :(得分:3)

用于加载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);