L
L
Lenar2016-10-24 15:05:20
JavaScript
Lenar, 2016-10-24 15:05:20

How to output a .txt file line by line (not a whole array) to a JSP page without using php and ajax?

<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.net.URL"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Read Text</title>
    </head>
    <body>
        <link rel="stylesheet" type="text/css" href="../style/style.css" />
        <div id="text">
            <h4 id="c2">MONITORING</h4>

            <a id="c1" href="<%=request.getContextPath()%>/LogoutUser">Выход</a>

            <%
                String txtFilePath = "C:/Users/Documents/config.txt";
                String lineSeparator = System.getProperty("line.separator");
                BufferedReader reader = new BufferedReader(new FileReader(txtFilePath));
                //BufferedReader br = new InputStreamReader(new FileInputStream(txtFilePath));
                StringBuilder sb = new StringBuilder();
                String line;

                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                out.println(sb.toString());
            %>
    </body>
</html>
Actually, the question itself is indicated in the title, I’ll just clarify that there is an authorization page on GlassFish for a specific platform, there is a jsp page from which it is necessary to implement viewing config.txt and, in the future, editing. Browsing on JSP works, but it displays everything as a solid array, not line-by-line output, I have already broken my head.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Lebedev, 2016-10-24
@RossarioAgro

Try this js api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question