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
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
我是用IDEA编译的,我把你的两个文件都放在了同一个package下。编译的过程中,一点问题都没有!
IDEA是什么呀?
如何放在一个package下呀?
我是菜鸟,请大家耐心讲解一下。小弟不胜感激
放到你的 jdk的lib目录下,设环境变量让它指向你的这个包
然后直接编译你的LongServlet.java 就可以了
只是你的环境变量找不到你的java.servlet.jar这个文件,
所以会报了好多找不到包的错误,
下到这个文件 设好环境变量就好了
如果你在C:\Java\coreservlets\ch05\WEB-INF\classes\coreservlets 里面放的这两个文件,只要在两个文件最上方写上
package coreservlets;
就可以了。
如果仍然不能compile, 肯定你的 CLASSPATH 没有设置正确。
在你的CLASSPATH里面一定要加上 C:\Java\coreservlets 路径,也就是你的开发路径。
关于你的设置检查,请查看第2章。
呵呵,我上个星期刚刚看完这一题。
我怎么找不到呀