新建的一个jsp页面如下,为什么结果是null?<%@ page language="java" import="java.util.*" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
   <% Servlet s = (Servlet)page; %>
    <%=s.getServletConfig().getServletContext().getServletContextName()%>
  </body>
</html>

解决方案 »

  1.   

    要得到 上下文的名字吗?可以写到web配置文件中。
      

  2.   

    就是在MyEclipse里新建的web project然后在webroot下新建了一个jsp页面,我想把page对象向下转型为Servlet,然后使用Servlet的一系列方法获得这个Servlet的名字,返回应该是这个Servlet的名字啊
      

  3.   

    page代表这个Servlet自己,它在Servlet里的定义是Object page = this;
      

  4.   

    <% Servlet s = (Servlet)page; %>
        <%=s.getServletConfig().getServletContext().getServletContextName()%>
    直接写为:《%=pageContext.getServletContext().getServletContextName()%>pageContext是jsp的内置对象,可以直接使用
      

  5.   

    <%=pageContext.getServletContext().getServletContextName()%>