<%@ page contentType = "text/html;charset=GB2312" %>
<%@ page import = "java.util.*" %><html>
<head>
</head>
<body>
<%
String s = pageContext.getServletContext().getServletInfo();
//String s = application.getServletInfo();
%>
</body>
</html>为什么会报错说
An error occurred at line: 9 in the jsp file: /home.jsp
The method getServletInfo() is undefined for the type ServletContext
6:  </head>
7:  <body>
8:  <%
9:  String s = pageContext.getServletContext().getServletInfo();
10:  //String s = application.getServletInfo();
11:  %>
12:  </body>

怎么会未定义......求解(包括被注释掉的方法也不行......)

解决方案 »

  1.   

    javax.servlet.jsp.PageContext
    javax.servlet.ServletContext   把这两个包引入进来试试。
      

  2.   

    不行....加了之后是这样吧:
    <%@ page contentType = "text/html;charset=GB2312"%>
    <%@ page import = "javax.servlet.jsp.PageContext" %>
    <%@ page import = "javax.servlet.ServletContext" %><html>
    <head>
    </head>
    <body>
    <%
    String s = pageContext.getServletContext().getServletInfo();
    %>
    </body>
    </html>
    依旧报错
    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 10 in the jsp file: /get.jsp
    The method getServletInfo() is undefined for the type ServletContext
    7:  </head>
    8:  <body>
    9:  <%
    10:  String s = pageContext.getServletContext().getServletInfo();
    11:  %>
    12:  </body>
    13: </html>

    依旧说未定义.......
      

  3.   

    看下包含此方法的jar包(多半是java EE)加入到项目classpath中了没同时也可以测下import其它类行不行
      

  4.   

    这家伙,PageContext是个抽象类,字母能直接调用它的方法。
    多看看API  public abstract class javax.servlet.jsp.PageContext
      

  5.   

    <%@ page contentType = "text/html;charset=GB2312"%> <%@ page import = "javax.servlet.jsp.PageContext" %> <%@ page import = "javax.servlet.ServletContext" %>   <html>     <head>     </head>     <body>         <%         String s = pageContext.getServletContext().getServletInfo();             %>     </body> </html> 
    pageContext里的p是不是应该大写呀?
      

  6.   

    哦貌似javax.servlet.ServletContext接口中没有getServletInfo方法
    javax.servlet.Servlet中才有不过也无须import这些类,在jsp中根本就没用到。这样用试试:
    <html>
        <body>
            <%= page.getServletInfo() %>
        </body>
    </html>