2011-01-31 5 views
0

애플릿이 포함 된 JSP 페이지에서 애플릿의 출력 스트림에 액세스하려고합니다. 그러나 그것은 NullPointerException을주고있다. 나는 아래 코드를 주었다.Jsp와 애플릿 통신

public class CheckJavaVersion extends Applet 
{ 
    private static final long serialVersionUID = 1L; 
private static Label versionCheck; 
    public static String javaVersion; 
    public static URLConnection connection; 

    public void init() 
    { 
     try 
     { 
      Color colFrameBackground = new Color(198, 0, 0); 
      this.setBackground(colFrameBackground); 
      versionCheck = new Label("Java Version:"+System.getProperty("java.version")); 
      this.add(versionCheck); 
      javaVersion = versionCheck.getText(); 
      javaVersion="testversion"; 

      String javaVersion1= URLEncoder.encode(javaVersion); 
      URL currentPage=getDocumentBase(); 
      String protocol=currentPage.getProtocol(); 
      String host=currentPage.getHost(); 
      int port=currentPage.getPort(); 
      String urlSuffix=currentPage.toString(); 
      URL dataurl=new URL(protocol,host,port,urlSuffix); 
      connection=dataurl.openConnection(); 
      connection.setUseCaches(false); 
      connection.setDoOutput(true); 
      connection.setDoInput(true); 
      ByteArrayOutputStream byteStream=new ByteArrayOutputStream(512); 
      PrintWriter out=new PrintWriter(byteStream,true); 
      out.print(javaVersion1); 
      out.flush(); 
      System.out.println(byteStream.toString()); 
      connection.setRequestProperty("Content-Length",String.valueOf(byteStream.size())); 
      connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
      byteStream.writeTo(connection.getOutputStream()); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

JSP 페이지

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Communication</title> 
</head> 
<body> 
<jsp:plugin code="com.applets.CheckJavaVersion" codebase="/AppletURLComm" type="applet"> 
</jsp:plugin> 

<% 
try 
{ 
    BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(CheckJavaVersion.connection.getInputStream())); 
    String data; 
    while((data=bufferedReader.readLine())!=null) 
    { 
     out.print(data); 
    } 
} 
catch (Exception e) 
{ 
    e.printStackTrace(); 
} 
%> 
</body> 
</html> 
+1

스택 트레이스는 항상 정보의 가치있는 작품이다. 어쨌든 ... 너는 이걸로 무엇을 하려니? – mdrg

+0

Related : http://stackoverflow.com/questions/4850351/applet-and-jsp-communication – BalusC

+0

[제거 된 의견] – mdrg

답변

0

당신은 JSP 페이지 스크립틀릿에서 애플릿에서 변수를 읽을 수 없습니다. 애플릿은 HTML이 클라이언트로 전송 된 후 클라이언트 브라우저에서 실행되는 자바 애플리케이션이므로 작동하지 않습니다.

SO 당신이 찾아 낼 여기에 조금 검색 : applet communication using post method

관련 문제