我们可以在web2py应用程序代码中使用Java代码吗? [英] can we use java code in web2py application code?

查看:84
本文介绍了我们可以在web2py应用程序代码中使用Java代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须实现一个web2py应用程序,该应用程序必须访问java代码(该代码具有连接到远程计算机的代码),但不确定是否可以在web2py中进行操作.我的电脑具有Java 1.6,Python2.7和web2py,已安装eclipse.

I have to implement one web2py application which has to access java code (which has code to connect to the remote machine) but not sure whether we can do it in web2py or not.My PC has Java 1.6, Python2.7 ,web2py ,eclipse installed.

用例是:

我已经在web2py应用程序中创建了一个按钮,单击该按钮后,它将实例化java对象并调用该java对象的特定方法,该方法将进一步连接到远程计算机.

I have created one button in web2py application and upon clicking the button, it should instantiate the java object and invoke particular method of that java object which will further connect to the remote machine.

疑问是:

  1. 我们可以将特定的Java类部署到web2py服务器上,以便web2py应用程序可以轻松访问它吗?

  1. Can we deploy that particular java class to web2py server so web2py application can easily access it?

是否可以从python代码导入该类?

Is it possible to import that class from python code?

如何从python代码实例化Java对象?

How to instantiate java object from python code?

以及如何从python代码调用Java方法?

And how to invoke java method from python code?

关于, 小猪

推荐答案

我会考虑研究Web服务. 如果您可以从Java公开URL,它将路由到执行逻辑并返回json对象的Java方法/函数. 在web2py urllib2中,您可以发出请求并将json解码为本地python字典. 提示是,您将必须公开对象的所有方法,并将对象作为json来回传递.在大多数编程语言中,不要害怕对象只是具有某些特殊性质的hash_arrays/dictionary.因此,如果您可以序列化和反序列化对象,并公开适当的url,那么就可以了.

I would consider looking into webservices. If you could expose url from java, that will route to a method/function of java where logic is performed and it returns json object. While in web2py urllib2 you can make a request and decode that json into native python dictionary. The clue is that you would have to expose all the methods of objects and pass the object back and forth as json. Do not be scared in most programming lanugages objects are just hash_arrays/dictionaries with some special qualities. So if you can serialize and deserialize the object and expose apriopriate urls you will be fine.

在jython中也有web2py的实现.但是,然后整个堆栈都将在JVM中,并且使用起来可能会更复杂.

Also there is implementation of web2py in jython. But then the entire stack will be in JVM and i may be more complex to work with.

这篇关于我们可以在web2py应用程序代码中使用Java代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆