アプリケーション固有のアプリケーションのビルドに参加すると、次のようなエラーが発生しました。誰か私のアプリで問題を見つけるのを手伝ってください。
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)
このエラーは、JPEGImageEncodeのインポートを示していますが、特定のサーブレットにすでにインポートしています。以下に続く最後の2つのエラー行。
851: <webproject2:javac destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/>
284:
これは私のキャプチャサーブレットです
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();
}
}