<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%
File f=new File("count.txt");
//FileReader fr=new FileReader(f);
%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
this is test
</body>
</html>这样可以打开,如果把注释去掉,就会出现“无法显示网页”
请问这是为什么?

解决方案 »

  1.   

    我改了一下代码:
    <%@   page   language="java"   contentType="text/html;   charset=ISO-8859-1" 
            pageEncoding="ISO-8859-1"%> 
    <!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=ISO-8859-1"> 
    <title> Insert   title   here </title> 
    </head> 
    <body>
       <% 
           File   f=new   File("count.txt"); 
          //FileReader   fr=new   FileReader(f); 
       %>  
    this   is   test 
    </body> 
    </html> 一般来说
    <%@   page   language="java"   contentType="text/html;   charset=ISO-8859-1" 
            pageEncoding="ISO-8859-1"%> 
    <!DOCTYPE   html   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"> 
    这两个部分是同时放在最前面的,然后:   <% 
           File   f=new   File("count.txt"); 
          //FileReader   fr=new   FileReader(f); 
       %> 
    这部分代码是放在<body> </body>标签里面的,
    这样改了之后就不会出现你刚才说的问题了
      

  2.   

    <%@       page       language="java"       contentType="text/html;       charset=ISO-8859-1"   
                    pageEncoding="ISO-8859-1"%>   
    <!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=ISO-8859-1">   
    <title>   Insert       title       here   </title>   
    </head>   
    <body> 
          <%   
                  File       f=new       File("count.txt");   
                //FileReader       fr=new       FileReader(f);   
          %>     
    this       is       test   
    </body>   
    </html>  
      

  3.   

    File       f=new       File("count.txt");  
    的路径有问题;
    String path = request.getRealPath("/");
    File f = new File(path+"count.txt");
    这样就能找到路径了
      

  4.   

    感谢各位,将代码放到<body>……</body>中我没有试,但是我解决的方法是:捕获异常。