当前位置: 代码迷 >> Java相关 >> 请教为什么编译不通过
  详细解决方案

请教为什么编译不通过

热度:259   发布时间:2013-02-25 21:47:35.0
请问为什么编译不通过
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();//为什么这里编译不通过
需要强制转换
  相关解决方案