0

当我参与构建应用程序特定应用程序时,我得到了类似这样的错误。任何人请帮助我在我的应用程序中找到问题。

warning: [options] bootstrap class path not set in conjunction with -source 1.6
D:\Sirojan's Files\OOP\AsiaHospital\src\java\com\asiahospital\servlet\captcha\CaptchaServlet.java:9: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGCodec;
D:\Sirojan's Files\OOP\AsiaHospital\src\java\com\asiahospital\servlet\captcha\CaptchaServlet.java:10: error: package com.sun.image.codec.jpeg does not exist
import com.sun.image.codec.jpeg.JPEGImageEncoder;
D:\Sirojan's Files\OOP\AsiaHospital\src\java\com\asiahospital\servlet\captcha\CaptchaServlet.java:40: error: cannot find symbol
            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
  symbol:   class JPEGImageEncoder
  location: class CaptchaServlet
D:\Sirojan's Files\OOP\AsiaHospital\src\java\com\asiahospital\servlet\captcha\CaptchaServlet.java:40: error: cannot find symbol
            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
  symbol:   variable JPEGCodec
  location: class CaptchaServlet
4 errors
1 warning
D:\Sirojan's Files\OOP\AsiaHospital\nbproject\build-impl.xml:851: The following error occurred while executing this line:
D:\Sirojan's Files\OOP\AsiaHospital\nbproject\build-impl.xml:284: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)

这个错误说 Import JPEGImageEncode 但我已经在特定的 Servlet 中导入。下面的最后两个错误行。

851: <webproject2:javac destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/>

284:

这是我的验证码 Servlet

package com.asiahospital.servlet.captcha;

import com.asiahospital.util.MyCaptchaService;
import com.octo.captcha.service.CaptchaServiceException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class CaptchaServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        byte[] captchaChallengeAsJpeg = null;
        // the output stream to render the captcha image as jpeg into
        ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
        try {
            // get the session id that will identify the generated captcha.
            // the same id must be used to validate the response, the session id
            // is a good candidate!
            String captchaId = request.getSession().getId();
            // call the ImageCaptchaService getChallenge method
            BufferedImage challenge = MyCaptchaService.getInstance().getImageChallengeForID(captchaId,
                    request.getLocale());

            // a jpeg encoder
            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
            jpegEncoder.encode(challenge);
        } catch (IllegalArgumentException e) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        } catch (CaptchaServiceException e) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        captchaChallengeAsJpeg = jpegOutputStream.toByteArray();

        // flush it in the response
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        ServletOutputStream os = response.getOutputStream();
        os.write(captchaChallengeAsJpeg);
        os.flush();
        os.close();





    }


}
4

1 回答 1

1

com.sun.image.codec.jpeg.JPEGCodec是 Sun 专有的 API,您不应使用它。我认为您应该阅读此线程并使用图像 I/O 重新实现。

于 2012-08-15T06:05:23.533 回答