2016-08-02 13 views
0

user.homeディレクトリのWindows 7にあるjsonファイルから情報を読み込む必要があります。これはjavascriptを使用したかったのです。しかし、Javascriptはjava webEngineを介したローカルドライブへのアクセスではありません。このためには、jsonファイルから情報を読み込むためにJavaクラスを使用し、結果を表示するにはjspを使用します。JSP on JavaFX WebEngine

Utils.java : 

public class AdminUtils{ 

    public String getBasStatus() { 
     try { 
      String userHomePath = System.getProperty("user.home"); 
      userHomePath = userHomePath + File.separator + "MY_PROJECT_FOLDER"; 
      String fileName = userHomePath + File.separator + "deviceStatus.json"; 
      File jsonFile = new File(fileName); 
      String jsonString = null; 
      jsonString = FileUtils.readFileToString(jsonFile); 
      JsonElement element = new JsonParser().parse(jsonString); 
      JsonObject jsonObject = element.getAsJsonObject(); 
      return jsonObject.get("billAcceptorStatus").toString(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return ""; 
     } 
    } 

    public String getPadStatus(){ 

     try { 
      String userHomePath = System.getProperty("user.home"); 
      userHomePath = userHomePath + File.separator + "MY_PROJECT_FOLDER"; 
      String fileName = userHomePath + File.separator + "deviceStatus.json"; 
      File jsonFile = new File(fileName); 
      String jsonString = null; 
      jsonString = FileUtils.readFileToString(jsonFile); 
      JsonElement element = new JsonParser().parse(jsonString); 
      JsonObject jsonObject = element.getAsJsonObject(); 
      return jsonObject.get("pinPadStatus").toString(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return ""; 
     } 

    } 
} 

これはdeviceStatus.jspです:

<%@ page import="util.AdminUtils" %> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta http-equiv="Cache-Control" content="no-store"/> 
    <meta http-equiv="Pragma" content="no-cache"/> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Device Status</title> 
    <style> 
     .defaultStatus { 
      width: 50px; 
      height: 50px; 
      display: block; 
      background: url("./../images/deviceStatusIcons/question.png") no-repeat; 
      background-size: contain; 
     } 

     .goodStatus { 
      width: 50px; 
      height: 50px; 
      display: block; 
      background: url("./../images/deviceStatusIcons/check.png") no-repeat; 
      background-size: contain; 
     } 

     .badStatus { 
      width: 50px; 
      height: 50px; 
      display: block; 
      background: url("./../images/deviceStatusIcons/delete.png") no-repeat; 
      background-size: contain; 
     } 
    </style> 
    <script> 
     <% 
     AdminUtils utils = new AdminUtils("username", "password"); 
     %> 
     var basStatus = <%=utils.getBasStatus()%> ; 
     var padStatus = <%=utils.getPadStatus()%> ; 

     function billAcceptorStatus() { 
      if (basStatus == 0) { 
       $("#billAcceptorStatus").attr('class', 'goodStatus'); 
      } else if (basStatus == 2) { 
       $("#billAcceptorStatus").attr('class', 'badStatus'); 
      } else { 
       $("#billAcceptorStatus").attr('class', 'defaultStatus'); 
      } 
     } 
     function pinPadStatus() { 
      if (padStatus == 0) { 
       $("#pinPadStatus").attr('class', 'goodStatus'); 
      } else if (padStatus == 2) { 
       $("#pinPadStatus").attr('class', 'badStatus'); 
      } else { 
       $("#pinPadStatus").attr('class', 'defaultStatus'); 
      } 
     } 
    </script> 
</head> 
<body> 
<div class="content"> 
    <div class="row"> 
     <div style="width:100%;height:150px;text-align: center;"> 
      <h2>DEVICE STATUS PAGE</h2> 
     </div> 
     <div style="width: 100%;height: 600px;"> 
      <table style="width: 60%;border-collapse:collapse;" align="center"> 
       <caption>DEVICE STATUSES</caption> 
       <tr style="border-bottom: 1px solid #adadad; background-color: #adadad"> 
        <td width="10%">№</td> 
        <td width="20%">Name</td> 
        <td width="20%">Status</td> 
       </tr> 

       <tr style="border-bottom: 1px solid #adadad;border-top: 1px solid #adadad; background-color: gainsboro"> 
        <td width="10%">1</td> 
        <td width="20%"> 
         <p>Pin Pad</p> 
        </td> 
        <td width="20%"> 
         <span id="pinPadStatus" class="defaultStatus"></span> 
        </td> 
       </tr> 

       <tr style="border-bottom: 1px solid #adadad;border-top: 1px solid #adadad; background-color: gainsboro"> 
        <td width="10%">2</td> 
        <td width="20%"> 
         <p>Bill Acceptor</p> 
        </td> 
        <td width="20%"> 
         <span id="billAcceptorStatus" class="defaultStatus"></span> 
        </td> 
       </tr> 

      </table> 
      <br/><br/> 
     </div> 
    </div> 
</div> 
</body> 
</html> 

これはdeviceStatus.jsonファイルです:

{"billAcceptorStatus":"-1","pinPadStatus":"-1"} 

これはwebengineへのコードのロードdeviceStatus.jspです:

if (Objects.equals(adminPassword.get(1), "4")) { 
      if (Objects.equals(adminPassword.get(2), "5")) { 
       if (Objects.equals(adminPassword.get(3), "6")) { 
        adminPassword.clear(); 
        webEngine.load(AtmApplication.class.getResource("/html/deviceStatus.jsp").toExternalForm()); 
        adminMode = false; 
       } else loadDefaultPage(); 
      } else loadDefaultPage(); 
     } 

しかしJ spファイルがwebEngineに読み込まれません。一緒にjspファイル - htmlファイルをロードする場合、webengineはhtmlファイルをロードしました。しかし、私はロードJSPファイルが必要です。

答えて

0

JSPはクライアント側の技術ではなく、サーバー側の技術です。それは、ブラウザがそれを表示できるように、サーバによってHTMLに変換されます。 JavaFXはクライアント側の技術であり、ブラウザと同様に、WebエンジンはJSPファイルではなくHTMLファイルのみを処理できます。

関連する問題