写一个JSP代理作为AIR和FLEX以及远程通信的桥梁

写一个JSP代理作为AIRFLEX以及远程通信的桥梁

【写在前面:】我本人也非常推荐使用JSP来构建FLEX的服务端,这样的应用架构不难理解而且也非常方便,扩充和维护起来都很简单

有的时候你无法将跨域的配置文件放置到一个目标服务器,那么这个时候你的C/S架构就会出现一些问题,如何来解决这些问题呢?你可以使用一个服务端的代理文件作为FLEX客户端加载远程数据的一个桥梁,和直接访问域上的资源不同,FLEX首先回去访问这些代理服务,然后由这个代理来尝试获得指定域上的资源。

这样的代理也可以通过使用JSP服务端语言来构建,脚本如下,将其保存为getrssurl.jsp并将其配置到服务端这样这个代理就可以工作了。

服务端代码:

<% @ page language="java" contentType="text/html; charset=utf-8"

pageEncoding
="utf-8"

import
="java.io.BufferedReader,

java.io.InputStreamReader,

java.io.IOException,

java.io.InputStream,

java.net.MalformedURLException,

java.net.URL,

java.net.URLConnection
"

%>

<% !

private String contentURL;

public static final String CONTENT_URL_NAME = "contentURL";

%>

<%

// 从request获得指定的要访问的URL:

If (contentURL 
==   null {

contentURL 
= (String)request.getAttribute(CONTENT_URL_NAME);

throw new ServletException("A content URL must be provided, as a

"'" + CONTENT_URL_NAME +

"'" request attribute or request parameter.");

URL url 
= null;

try {

//获得到该内容的连接:

url 
= new URL(contentURL);

URLConnection urlConn 
= url.openConnection();

//向客户端展示文档内容:

String contentType 
= urlConn.getContentType();

response.setContentType(contentType);

// 获得输入流

InputStream 
in = urlConn.getInputStream();

BufferedReader br 
= new BufferedReader(new InputStreamReader(in));

char[] buffer = new char[1024];

String contentString 
= "";

String tmp 
= br.readLine();

do

{

contentString 
+= tmp + " ";

tmp 
= br.readLine();

}


while (tmp != null);

out.flush();

out.close();

}


catch (MalformedURLException me) {

// 新的URL到来的时候:

throw new ServletException(å

"URL: '" + contentURL + "' is malformed.");

}


catch (IOException ioe) {

//在创建新的连接的时候:

throw new ServletException("Exception while opening '" +å

contentURL 
+ "': " + ioe.getMessage());

}


catch (Exception e) {

//在读入输入的时候:

throw new ServletException("Exception during proxy request: " å

+ e.getMessage());

}


%>

 

FLEX客户端,你要做的唯一一件事情就是将HTTP标签的目标URL进行修改,指向该JSP文件即可

客户端代码

< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml "

layout
= " vertical "  creationComplete = " myHS.send() " >

< mx:HTTPService id = " myHS "

url
= " http://88.149.156.198/develop/xmloutput/getrssurl.jsp "

method
= " GET " å

result
= " myAS = myHS.lastResult.rss.channel.item as ArrayCollection " >

< mx:request xmlns = "" >

< url > {myURL} </ url >

</ mx:request >

</ mx:HTTPService >

< mx:DataGrid id = " myDG "  dataProvider = " {myAS} " >

< mx:columns >

< mx:DataGridColumn dataField = " category "  headerText = " Category "   />

< mx:DataGridColumn dataField = " title "  headerText = " Description "   />

< mx:DataGridColumn dataField = " pubDate "  headerText = " Date "   />

</ mx:columns >

</ mx:DataGrid >

</ mx:Application >

保存这些文件,然后将SWFHTML包裹代码作为客户端,JSP文件作为服务端,装载该LFEX程序的话你就可以看见RSS FEED显示在应用程序中

 

源文档 <http://casario.blogs.com/mmworld/2008/02/write-a-jsp-pro.html>

 

Write a JSP proxy which acts as a bridge between the Flex and AIR applications and the remote data

Sometimes you won’t be able to put a cross-domain file on the destination server. To solve

this problem you can use a server-side proxy file that consists of a script published on the

server which acts as a bridge between the Flex application and the remote data to load. Instead of directly accessing external resources on different domains, Flex will access this proxy service, which looks after accessing the resources on the specified domains.

The same proxy method can also be created by using JSP as server-side language. Create a

new file and save it with the name getrssurl.jsp.  The script is the following:

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"

import="java.io.BufferedReader,

java.io.InputStreamReader,

java.io.IOException,

java.io.InputStream,

java.net.MalformedURLException,

java.net.URL,

java.net.URLConnection"

%>

<%!

private String contentURL;

public static final String CONTENT_URL_NAME = "contentURL";

%>

<%

// get the url through the request:

If (contentURL == null) {

contentURL = (String)request.getAttribute(CONTENT_URL_NAME);

if (contentURL == null)

contentURL = (String)request.getParameter(CONTENT_URL_NAME);

}

if (contentURL == null)

throw new ServletException("A content URL must be provided, as a

"'" + CONTENT_URL_NAME +

"'" request attribute or request parameter.");

URL url = null;

try {

// get a connection to the content:

url = new URL(contentURL);

URLConnection urlConn = url.openConnection();

// show the client the content type:

String contentType = urlConn.getContentType();

response.setContentType(contentType);

// get the input stream

InputStream in = urlConn.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(in));

char[] buffer = new char[1024];

String contentString = "";

String tmp = br.readLine();

do

{

contentString += tmp + "/n";

tmp = br.readLine();

}

while (tmp != null);

out.flush();

out.close();

}

catch (MalformedURLException me) {

// on new URL:

throw new ServletException(å

"URL: '" + contentURL + "' is malformed.");

}

catch (IOException ioe) {

// on opne connection:

throw new ServletException("Exception while opening '" +å

contentURL + "': " + ioe.getMessage());

}

catch (Exception e) {

// on reading input:

throw new ServletException("Exception during proxy request: " å

+ e.getMessage());

}

%>

Save this file as getrssurl.jsp and transfer it onto the web server.

On the Flex side the only thing you have to change is the address defined within the url

property of the HTTPService tag. The url has to point to the JSP file:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="vertical" creationComplete="myHS.send()">

<mx:HTTPService id="myHS"

url="http://88.149.156.198/develop/xmloutput/getrssurl.jsp"

method="GET"å

result="myAS = myHS.lastResult.rss.channel.item as ArrayCollection">

<mx:request xmlns="">

<url>{myURL}</url>

</mx:request>

</mx:HTTPService>

<mx:DataGrid id="myDG" dataProvider="{myAS}">

<mx:columns>

<mx:DataGridColumn dataField="category" headerText="Category" />

<mx:DataGridColumn dataField="title" headerText="Description" />

<mx:DataGridColumn dataField="pubDate" headerText="Date" />

</mx:columns>

</mx:DataGrid>

</mx:Application>

Save the file, run the application, and then copy the SWF file with the HTML Wrapper and

the JSP file onto a web server. Load the application to see the RSS feed displayed in the

Flex application.

Posted by marco casario on February 20, 2008 at 01:16 AM in Flex, Flex 2 Best Practice | Permalink

Comments

I end up using proxies like this way more than I'd like to, but alas, it's what we have to do.

one trick i like to use is to put the proxying into an error handler, so that if the site ever adds a crossdomain file, i can take advantage of direct access without having to change the code. It does add an extra request but can be handy.

myurlloader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,tryProxy);

Posted by: Daryn | February 20, 2008 at 02:05 AM

 

源文档 <http://casario.blogs.com/mmworld/2008/02/write-a-jsp-pro.html>

 

 

 

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值