日期:2014-05-20  浏览次数:20757 次

请问为什么编译不通过
Java code

package  com.nong;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ServletContext extends  HttpServlet {

public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
    try{
        res.setContentType("text/html;charset=gbk");
        PrintWriter pw=res.getWriter();
        ServletContext sc=this.getServletContext();//为什么这里编译不通过
        }
    catch(Exception e)
    {e.printStackTrace();}
}

public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
    this.doGet(req,res);
}

    
}






------解决方案--------------------
ServletContext sc=this.getServletContext();//为什么这里编译不通过
需要强制转换