我正在尝试使用Flex将文件从客户端的浏览器上传到服务器。我已经使用FileReference类调用了一个执行上传的.For。下面是uploadHandler函数的代码。
private function uploadHandler(event:Event):void
{
var url:String="http://localhost/upload/WelcomeServlet";
var request:URLRequest=new URLRequest(url);
request.method=URLRequestMethod.POST;
var variables:URLVariables=new URLVariables();
variables.employeeID="sam";
request.data=variables;
file.upload(request);
}正如URLRequest处理http请求一样,我在tomcat服务器的根文件夹中添加了网络策略文件crossdomain.xml .below是xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="All"/>
<allow-access-from domain="*" secure="false" />
</cross-domain-policy>在尝试上传文件时,我仍然收到以下错误:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2049: Security sandbox violation: http://mysite.com/upload/upload.swf cannot upload data to http://localhost/upload/WelcomeServlet.
at upload/creationCompleteHandler()[C:\Users\Documents\Flex Builder 3\upload\src\upload.mxml:22]
at upload/___upload_Application1_creationComplete()[C:\Users\Documents\Flex Builder 3\upload\src\upload.mxml:4]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
at mx.core::UIComponent/set initialized()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169]
at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]当我尝试从本地主机上传时,它工作得很好。我需要添加任何额外的编译器参数吗?我使用的是flash player 10和apache tomcat 6.0.20。这个错误已经困扰我很长一段时间了,如果有任何帮助,我将不胜感激
谢谢sanre6
发布于 2011-05-05 18:24:21
为什么不更改此字符串:
var url:String="http://localhost/upload/WelcomeServlet";至:
var url:String="/WelcomeServlet";https://stackoverflow.com/questions/5896110
复制相似问题