public String APIExamCaptchaImage(String key) {

String clientId = "ㅇㅇ";// 애플리케이션 클라이언트 아이디값";

String clientSecret = "ㅇㅇ";// 애플리케이션 클라이언트 시크릿값";

String tempname = null;

StringBuffer response = null;

try {


//String key2 = key; // https://openapi.naver.com/v1/captcha/nkey 호출로 받은 키값

String apiURL = "https://openapi.naver.com/v1/captcha/ncaptcha.bin?key=" + key;</p><p><span style="white-space:pre"> URL url = new URL(apiURL);

HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setRequestMethod("GET");

con.setRequestProperty("X-Naver-Client-Id", clientId);

con.setRequestProperty("X-Naver-Client-Secret", clientSecret);

int responseCode = con.getResponseCode();

BufferedReader br;

if (responseCode == 200) { // 정상 호출

InputStream is = con.getInputStream();

int read = 0;

byte[] bytes = new byte[1024];

// 랜덤한 이름으로 파일 생성

tempname = Long.valueOf(new Date().getTime()).toString();

File f = new File("tempname" + ".jpg");

f.createNewFile();

OutputStream outputStream = new FileOutputStream(f);

while ((read = is.read(bytes)) != -1) {

outputStream.write(bytes, 0, read);

}

is.close();

} else { // 에러 발생

br = new BufferedReader(new InputStreamReader(con.getErrorStream()));

String inputLine;

response = new StringBuffer();

while ((inputLine = br.readLine()) != null) {

response.append(inputLine);

}

br.close();

}

} catch (Exception e) {

System.out.println(e);

}

//return tempname;

return tempname;

}













<%

String contextRoot = request.getContextPath();

Key m= new Key();

String key2 = m.APIExamCaptchaNkey();

key2 = key2.substring(8,24);

String tempname = m.APIExamCaptchaImage(key2);

tempname = String.format(""%s.jpg"",tempname);


%>




<div class="container">


<h1>index page</h1>

<%=key2 %><br>

<%=tempname %><br>

<img src=<%=tempname %>>

</div>




이미지 태그 주소에 파일명쑤셔박으면 이미지 자동으로 불러온다는데
난 이미지를 못 불러옴. 키랑 파일명은 제대로 받아오고 있는데.


콘솔창에

{"key":"dP21bLJDIZtIGlW2"}
java.io.IOException: 액세스가 거부되었습니다



실행할때마다 저거 뜨는거보면 저게 문제인거같기도 한데
뭘 고쳐야됨?
저 위에 자바소스는 네이버 개발자센터 샘플 소스복붙해서 리턴값만 받아올 수 있게 
수정한거라 만진건 없다고 봐도 무방한데.

프알못한테 도움좀