2012-11-06 110 views
1
  • 這是我的代碼。
  • 我使用一種簡單的方法來製作POST httprespon。
  • 安裝在小程序上。
  • 我在Eclipse中正常工作。
  • 但掛載在appletviewer導致擊落。
  • 網頁也會被擊落。
  • 數據量太大而無法處理?
  • 還是有其他原因嗎?
  • 我需要幫助謝謝Java applet使用httprespon

    public class we extends Applet 
    { 
    Button sd = new Button("11"); 
    Label title= new Label(); 
    Label prompt = new Label(); 
    TextField input = new TextField(8); 
    Label result = new Label(); 
    
    public void init() 
    { 
        add(sd); 
         } 
    
    public void start() { 
    
    } 
    
    public void paint (Graphics g) { 
    
    } 
    
    public boolean action(Event e, Object o) { 
        if (e.target == input) { 
         match(); 
        } else if (e.target == sd) { 
         abandon(); 
        } 
        return true; 
    } 
    private void match() {  
    } 
    private void abandon() { 
        String url="http://119.14.80.132/ACT_ID_355"; 
    
    HttpPost httppost=new HttpPost(url); 
    
    List<NameValuePair> params=new ArrayList<NameValuePair>(); 
    
    params.add(new BasicNameValuePair("UNCLOSE1","1")); 
    
    try { 
        httppost.setEntity(new UrlEncodedFormEntity(params,HTTP.ISO_8859_1)); 
    } catch (UnsupportedEncodingException e1) { 
    
        e1.printStackTrace(); 
    } 
    
    HttpResponse response = null; 
    try { 
        response = new DefaultHttpClient().execute(httppost); 
    } catch (ClientProtocolException e1) { 
    
        e1.printStackTrace(); 
    } catch (IOException e1) { 
    
        e1.printStackTrace(); 
    } 
    
    if(response.getStatusLine().getStatusCode()==200){ 
        try { 
         String resultq=EntityUtils.toString(response.getEntity()); 
        } catch (ParseException e1) { 
    
         e1.printStackTrace(); 
        } catch (IOException e1) { 
    
         e1.printStackTrace(); 
        } 
    } 
    
    } 
    

    }

的appletviewer

Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: acc 
ess denied ("java.net.SocketPermission" "119.14.80.132:80" "connect,resolve") 
     at java.security.AccessControlContext.checkPermission(AccessControlConte 
xt.java:366) 
     at java.security.AccessController.checkPermission(AccessController.java: 
560) 
     at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) 
     at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051) 
     at java.net.Socket.connect(Socket.java:574) 
     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSoc 
ketFactory.java:127) 
     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnect 
ion(DefaultClientConnectionOperator.java:180) 
     at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedCli 
entConnectionImpl.java:294) 
     at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(Default 
RequestDirector.java:640) 
     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultReq 
uestDirector.java:479) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpCl 
ient.java:906) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpCl 
ient.java:805) 
     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpCl 
ient.java:784) 
     at we.abandon(we.java:130) 
     at we.action(we.java:49) 
     at java.awt.Component.handleEvent(Component.java:6751) 
     at java.awt.Component.postEvent(Component.java:5160) 
     at java.awt.Component.postEvent(Component.java:5170) 
     at java.awt.Component.dispatchEventImpl(Component.java:4877) 
     at java.awt.Component.dispatchEvent(Component.java:4687) 
     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723) 
     at java.awt.EventQueue.access$200(EventQueue.java:103) 
     at java.awt.EventQueue$3.run(EventQueue.java:682) 
     at java.awt.EventQueue$3.run(EventQueue.java:680) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo 
main.java:76) 
     at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo 
main.java:87) 
     at java.awt.EventQueue$4.run(EventQueue.java:696) 
     at java.awt.EventQueue$4.run(EventQueue.java:694) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo 
main.java:76) 
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:693) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre 
ad.java:244) 
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread. 
java:163) 
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre 
ad.java:151) 
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147) 

     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139) 

     at java.awt.EventDispatchThread.run(EventDispatchThread.java:97) 

回答

1

一個applet的 '沙箱' 中運行。它只允許打開一個到它下載的服務器的連接。您看到的錯誤是安全違規,因爲您正嘗試連接到另一臺服務器。

+0

那麼我該怎麼做呢? 添加到JAR簽名自定義安全性? 那麼沒有違反安全簽名會直接導致擊落的結果? –

+0

您可以簽署您的小程序,但您需要證書(昂貴)或用戶需要接受不可信的可執行代碼(極不可能)。然而,更好的方法是連接到始發服務器。將您的小程序放在服務器上(比如說http://119.14.80.132),並且只連接到該服務器。如果您需要來自其他服務器的數據,請在始發服務器(從中提供小應用程序的位置)上實施代理以從其他服務器檢索數據,以便小應用程序仍然只需連接到始發服務器。 – Janoz

+0

我已經成功安裝了一個簽名。 但問題沒有解決。 C:\ Program Files文件\的Java \ jdk1.7.0_09 \ BIN>的jarsigner - 密鑰庫角落,Storepass用於654321 -keypass 654321 se.jar確定 警告: 的簽名證書將在六個月內到期。 –

0

已回答。 我覺得很愚蠢。 我花了十幾個小時不想出來。 答案實際上只是一行文字。

public void init() 
{ 
System.setSecurityManager(null); 
add(sd); 
add(sd2); 
} 

我仍然無法理解爲什麼?????????