[英]Java applet use 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)
小程序在“沙箱”中运行。 仅允许打开与从中下载服务器的连接。 您看到的错误是安全冲突,因为您尝试连接到另一台服务器。
已回答。 我感到很愚蠢。 我花了十几个小时不想出来。 答案实际上只是一行文字。
public void init()
{
System.setSecurityManager(null);
add(sd);
add(sd2);
}
我还是不明白为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.