Java (JSP) 不打印出 "0x0a" 或在 system.out.println 中"n"新行



好的,首先,我正在开发一个OCR。Tesseract 在 txt 文件中向我返回了一大块字符串。我应该读取文本文件并将其显示在 jsp 上。

目前,在Windows记事本上查看时,我的文本是这样的:

Hello World!This is a sample text.

在记事本++上查看:

Hello World!
This is a sample text.

当我通过读取文件在 jsp 中运行我的代码(如下所示)时,它显示的就像 Windows 记事本显示的那样,而不是像 Sublime 文本编辑器。我希望文本换行,而不是连接在一起。

<%
            String file_name=(String)request.getParameter("file_name");
            String file_name_given=(String)request.getParameter("file_name_given");
            //creating the out put file after upload and reading
            create_file obj_create_file=new create_file();
            obj_create_file.create_output_file(file_name);
            //read the created out put file
            read_file obj_read_file=new read_file();
            String read=obj_read_file.read_file(file_name);
            System.out.println(read);
%>

如何以显示隔断线而不是连续字符串的方式修改代码?我怀疑这与 ASCII 字符"0x0a"有关。

您从 JSP 发送到浏览器的内容通常被解释为 HTML。 在 HTML 中,换行符只是空格。 他们不会给你换行符。

要在 HTML 中获取换行符,您需要输出<br><p>或类似的东西。 如果这没有为你"敲响任何警钟",我建议你找到并阅读HTML教程或教科书

最新更新