[英]Retrieve hashmap values from java servlet to flex
I am working on "migration from JSP to FLEX, and java as back-end. I am novice in java and JSP. 我正在研究“从JSP到FLEX的迁移,并将Java作为后端。我是Java和JSP的新手。
I am stuck at getting values from a java servlet where it takes httprequest and there is a function called forward(request,response)
which responds as JSP page with requried values in it. 我被困在从Java Servlet获取值的过程中,它使用httprequest,并且有一个名为
forward(request,response)
的函数forward(request,response)
它以JSP页面的形式forward(request,response)
其中的查询值。
Now I need to change that and get only data from that servlet and use that in flex. 现在,我需要更改它,仅从该servlet获取数据,然后在flex中使用它。
Problem: 问题:
case1: When using httpservice it takes result as string, but unable to get as object. 情况1:使用httpservice时,将结果作为字符串,但无法作为对象获取。
case2: If I use RemoteObject , it needs method in java servlet to get return value, which is not present in existing servlet. 案例2:如果我使用RemoteObject,则它需要java servlet中的方法来获取返回值,而该返回值在现有servlet中不存在。
Can I get any suggestions on this problem. 我可以就这个问题得到任何建议吗?
Thank You 谢谢
case1: you don't use forward anymore, you set the type of data you want to return, for example: 情况1:您不再使用转发,而是设置要返回的数据类型,例如:
response.setContentType("application/json");
... and returning data in servlet is done by writing data to a stream like: ...并通过将数据写入流中来完成servlet中的返回数据:
PrintWriter out = response.getWriter();
out.print(object);
but it's a while ago since I did this, so there may be some small problem you will face... 但是距我这样做已经有一段时间了,所以您可能会遇到一些小问题...
case2: if you are using servlet, it's correct to use HTTPService, RemoteObject will not work, it is used differently.... case2:如果您使用的是servlet,则使用HTTPService是正确的,RemoteObject将不起作用,使用方式有所不同。
Now, if I can, I would suggest diferent thing to use than servlets - to obtain data from a java server to Flex - I love to use GraniteDS. 现在,如果可以的话,我建议使用比servlet小得多的东西-从Java服务器获取数据到Flex-我喜欢使用GraniteDS。
I will just state some benefits I see, in case you are interested: 如果您有兴趣,我只想说说我看到的一些好处:
It is easy to setup: - in java, you will just add a graniteDS library, two config files (granite+services-config xmls) add a granite servlet config to web.xml - in flex there is also granite library and services-config.xml 设置很容易:-在Java中,您只需添加graniteDS库,两个配置文件(granite + services-config xmls)将granite servlet配置添加到web.xml-在flex中,还有Granite库和services-config .XML
When set up, using it is also flowleslly easy - you have a class with a method (or simple bean or ejb) in Java which just return an object of any type! 设置后,使用它也非常容易-您在Java中有一个带有方法(或简单bean或ejb)的类,该类仅返回任何类型的对象! And that's it in Java
在Java中就是这样
In flex, in this case you use RemoteObject which you just call that remote java method and in result handler you get your dataGranite will take care of serializing+transfer+deserializing and just give you the Object (either just dynamic {} or even exact class type) 在flex中,在这种情况下,您使用的是RemoteObject,您只需调用该远程java方法,然后在结果处理程序中获取dataGranite即可进行序列化+传递+反序列化,并只给您Object(可以是动态{}甚至是精确的类类型)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.