Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在jsp页面中读取和显示本地文本文件时出错_Java_File_Jsp - Fatal编程技术网

Java 在jsp页面中读取和显示本地文本文件时出错

Java 在jsp页面中读取和显示本地文本文件时出错,java,file,jsp,Java,File,Jsp,这是我的index.jsp页面代码[这个问题是这样的: 注意:我的IDE是eclipse,我的web服务器是Tomcat7.0。 但是这些代码没有任何输出,为什么?您在第1行和第4行使用了多个页面指令。请使用其中一个。然后检查下面更新的代码 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%> <%@page import="java.i

这是我的
index.jsp
页面代码[这个问题是这样的:


注意:我的IDE是eclipse,我的web服务器是Tomcat7.0。
但是这些代码没有任何输出,为什么?

您在第1行和第4行使用了多个页面指令。请使用其中一个。然后检查下面更新的代码

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="java.io.*"%>
<%@page import="java.net.URL"%>
 <!-- @page contentType="text/html" pageEncoding="UTF-8" --> <!--When I use this line has conflict error -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
    <%
        String jspPath = "C:\\Users\\Farshid\\workspace\\STPT\\WebContent\\file\\title.txt";
        BufferedReader reader = new BufferedReader(new FileReader(jspPath));
        //BufferedReader br = new InputStreamReader(new FileInputStream(txtFilePath));
        StringBuilder sb = new StringBuilder();
        String line;

        line = reader.readLine();
        out.println(sb.toString());
        System.out.println("line" +line);
    %>
 <%=line %>

</title>

</head>
<body>
<p> <%=line %></p>
</body>
</html>


否,我的文本文件已联机
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="java.io.*"%>
<%@page import="java.net.URL"%>
 <!-- @page contentType="text/html" pageEncoding="UTF-8" --> <!--When I use this line has conflict error -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
    <%
        String jspPath = "C:\\Users\\Farshid\\workspace\\STPT\\WebContent\\file\\title.txt";
        BufferedReader reader = new BufferedReader(new FileReader(jspPath));
        //BufferedReader br = new InputStreamReader(new FileInputStream(txtFilePath));
        StringBuilder sb = new StringBuilder();
        String line;

        line = reader.readLine();
        out.println(sb.toString());
        System.out.println("line" +line);
    %>
 <%=line %>

</title>

</head>
<body>
<p> <%=line %></p>
</body>
</html>