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

关于无常正常编译servlet文件的问题.急.顺便说下导包的方法.
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;
import   java.util.zip.*;

public   class   GzipUtilities
{
public   static   boolean   isGzipsupported(HttpServletRequest   request)   {
String   encodings   =   request.getHeader( "Accept-Encoding ");
return((encodings   !=   null)   &&   (encodings.indexOf( "gzip ")   !=   -1));
}
public   static   boolean   isGzipDisabled   (HttpServletRequest   request)   {
String   flag   =   request.getParameter( "disableGzip ");
return((flag   !=   null)   &&   (!flag.equalsIgnoreCase( "false ")));
}

public   static   PrintWriter   getGzipWriter
(HttpServletResponse   response)   throws   IOException   {
return(new   PrintWriter(new   GZIPOutputStream(response.getOutputStream())));
        }
}这个GzipUtilities.java文件可以编译
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;

public   class   LongServlet   extends   HttpServlet
{
public   void   doGet(HttpServletRequest   request,HttpServletResponse   response)
throws   ServletException,IOException   {
response.setContentType( "text/html ");
PrintWriter   out;
if   (GzipUtilities.isGzipsupported(request)   &&   (!GzipUtilities.isGzipDisabled(request)))  
{
out   =   GzipUtilities.getGzipWriter(response);
response.setHeader( "Content-Encoding ", "gzip ");
        }   else   {
out   =   response.getWriter();
}
out.println
  ( " <HTML> \n "   +
    " <HEAD> <TITLE> "   +   "asadzd "   +   " </TITLE> </HEAD> \n "   +
    " <BODY   BGCOLOR=\ "#FDF5E6\ "> \n "   +
    " <H1   ALIGN=\ "CENTER\ "> "   +   "GZIP   Data "   +   " </H1> \n ");
String   line   =   "Blah,blah,blah,blah,blah, "   +
"Yadda,Yadda,yadda,yadda. ";
for(int   i   =   0   ;i <10000;i++)   {
out.println(line);
}
  out.println( " </BODY> </HTML> ");
  out.close();
}
}
这个LongServlet.java文件无法编译了.无法使用GzipUtilities.java的方法,我问我同学,说是要导包,导包后就可以识别GzipUtilities.java的方法,不知道如何导包,我只知道我脑袋急的满头是包.
兄弟请帮帮忙,帮我讲解一下如何正常的编译LongServlet.Java文件,顺便说下导包
我用的是EditPlus

------解决方案--------------------
你这是coreservlets第5章的题目。
如果你在C:\Java\coreservlets\ch05\WEB-INF\classes\coreservlets 里面放的这两个文件,只要在两个文件最上方写上
package coreservlets;
就可以了。
如果仍然不能compile, 肯定你的 CLASSPATH 没有设置正确。
在你的CLASSPATH里面一定要加上 C:\Java\coreservlets 路径,也就是你的开发路径。
关于你的设置检查,请查看第2章。
呵呵,我上个星期刚刚看完这一题。