0

I need read information from json file which is located in user.home directory Windows 7. For this I wanted use javascript. But Javascript is not access to a local drive through java webEngine. For this I use java Class for read information from json file, and with jsp for showed result.

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 "";
        }

    }
}

this is a 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>

this is a deviceStatus.json file:

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

this is code loading deviceStatus.jsp to webengine:

   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();
        }

But jsp file is not loaded to webEngine. If together jsp file - load html file, webengine loaded html file. But I need load jsp file.

1 Answer 1

0

JSP is a server side technology not a client side technology. It gets transformed to HTML by the server so browsers can display it. JavaFX is a client side technology and like browsers the web engine can only handle HTML files, not JSP files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.