jQuery - run perl script (all standalone) - javascript

I have script Perl and for the moment this script is called with a simple batch file.
To make this interface more attractive, I'm looking for a language for create a GUI.
My first idea is to use jQuery/jQuery UI.
Before starting to learn, I want to know if is it possible to run a script perl with jQuery(UI).
fyi, I haven't Web server all code is standalone.
Of course, I'm interested if you have an idea for another language.
Thank's for your help.

jQuery is a JavaScript library for use in web pages. The primary way for JavaScript in a web page to interact with a Perl program is through HTTP (typically by using the XMLHttpRequest object to make an HTTP request). The HTTP server is responsible for running the Perl code (e.g. through PSGI, FastCGI, mod_perl, CGI or having a server written in Perl in the first place).
Without a web server, it isn't possible for a typical environment.
(There are exceptions, but they usually involve the browser being driven by Perl using something like Selenium).

Related

HTML Javascript and Java runtime communication

My group has a project that is upposed to connect a web page to a databse. the webpage is written in html, css, and javascript, and the database is written in mysql. we know there are issues with accessing databases from javascript, so we built a driver class from java that is supposed to control communication between the two.
the problem is that we do not know how to connect javascript with java during runtime. the way it is built, the javascript simply needs to call a java function and get the results. is there any simple way to do this? perhaps a certain library? we have little to no knowledge of other similar tools (i.e. jsp, xml) and would like to stick to the languages listed above.
You can create a Java HTTP JSON server and then make a call to it from Javascript by using AJAX calls.
See here: Java simple HTTP JSON server
In order to provide easy access to java code(including static/dynamic web content) over HTTP interface you've to use one of the (servlet) containers - jetty, tomcat, spring-boot, etc.
In my opinion, since you've minimal experience developing/deploying java web applications jetty might be good option as it have good documentation to get started. Spring Boot is popular choice for Enterprise web development using Java - it might be more than you want to chew for the moment.
The Servlet(web) and JDBC(database) APIs what you will end up using on Java side.

Does node.js replace tomcat?

If I can build a server with node.js do I need tomcat?
Excuse me, I'm a pretty new to it and I'd like to understand this base concepts. Thank you so much!
No, you do not need Tomcat if you are using Node. You could run one or the other, or both at the same time as long as they are not trying to listen on the same port. Here's why.
Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.
Basically, this means that Tomcat is designed specifically to be a web server.
Node is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Basically, this means that Node can take JavaScript code, optimize it, and give the code access to things that aren't normally exposed to JavaScript code that is run in a web browser, like direct access to the file system. JavaScript is similar to Python, lacking strict data typing, but unlike Python which is an interpreted language, Node reads JavaScript and turns it into machine code which does not require it to be interpreted before it is executed (so it can be much faster).
Node happens to be good for developing servers especially when using frameworks like Express, sort of like Rails for Ruby, or Flask for Python, but you can write anything you want, it doesn't have to be a server.

How to run JavaScript as a server side script language on SourceForge.NET?

As I known, JavaScript is a client-side scripting language. But, some days ago, I have heared that JavaScript is a server-side script language.
I don't understand about it... To know it, I have search Google, and I known that Node.JS can be used as a server-side script language. I have run some script with Node.JS (on Windows XP) successfully.
So, I tried to run it with a real server... I have posted all script (which are written in Node.JS) into SourceForge.NET. But, I don't know how do run it?
Can you help me to answer: "Does SourceForge.NET supports Node.JS? If can, please show me how to run with this server?".
I tried to run it with SourceForge.NET for only fun.
Node.js is a means of running JavaScript programs. It is commonly used to write HTTP servers.
If you have written code to use Node.js then you need to run it with Node.js for it to work.
If you want to involve some other kind of server then you would have to proxy requests made to it onto Node.js (e.g. with Apache's ProxyPass directive)… but that typically eliminates the reasons that people choose to use Node.js in the first place.
If you want to use Node.js in production then you will usually need to be hosting your site on a VM or a dedicated server. Shared hosting won't usually give you enough access to run Node.js.

loading native addons on client side

Is it possible to load native add-ons (written in C/C++ like in nodejs) from client side javascript using requireJS or some other module?
I am writing a nodejs + express app that serves an html file which loads javascript files. I am using requireJS and compiling these client-side js files into AMD module. I can load and call native methods from the nodejs server side js scripts and wondering if its possible to do the same from the client side js scripts.
No, you can't force the client to execute a native application via the browser like that. It would present a very large security hole that would allow any hacker to come along and execute arbitrary violent code on any client and this is strictly prevented. You can execute the C++ add-on on the server side via an API though, and that should solve most use cases.
RequireJS is not the driving factor in what you are trying to achieve. The capability to load native code is solely dependent on whether the JavaScript VM that runs your code allows it or not. If the VM does not allow it, RequireJS cannot add this capability.
You can do it in Node because Node allows it.
Browsers are much more restrictive as to what they allow. A JavaScript script executing in a web page won't generally be able to load native code because, as Chris Franklin explained, it is a security hole.
One way to get the functionality provided by a C or C++ library to run browser-side is to use something like Emscripten to compile the C or C++ code to JavaScript.

Integrating ECMA Script into a C# program, what is the fastest technique?

I'm trying to execute JavaScript in a C# program, and I'm trying to determine:
Would it be better to create a state machine for JavaScript, or should it be compiled into MSIL before executing it?
I'm really looking for techniques rather than solutions. Some attempt to compile the JavaScript, there by treating it as a programming language, others use a state machine and treat it as it was meant to be : a scripting language.
Any documentation on the methods used for executing is welcome also.
The easiest way to run JS in a C# program is to use one of the existing .Net JS runtimes: IronJS, Jurassic, and Jint. If you're interested in adding another .Net-based interpreter to the mix, examining their code is where I'd start; If you're embedding JS in your program then using a preexisting one is probably the way to go.
You haven't explained your scenario - how much javascript, how often does it get executed, how often does it change, how closely integrated it needs to be with the C# logic, and so on.
If it rarely changes, then it may be smart to compile it into MSIL via one of the alternatives.
If it changes "constantly" then it might make sense to stand up a JS compiler and send it JS as necessary. It's something like a REPL for Javascript, that you'd use programmatically. Node.js offers a server that can do REPL operations; it could listen on a port, you send it JS to evaluate, and it sends back the result. There's a free w3sockets component that could be used from cscript.exe to do something similar: for example you could build a "host" Javascript shell that listens on a socket, executes the js it receives, then sends back the result.
If it needs to be closely integrated with the C# code, then you'll have to be smarter about this. One way to do it might be to host the JS in a Windows Script Component and have the C# code invoke the JS logic via COM. You can also do the converse - have the JS host invoke the C# layer via COM to gather input and deliver results.
EDIT
A better way is to use the IActiveScript stuff - this is the official way Microsoft makes it possible to host scripting within an application. There's a winforms example published here.
OR better, see parse and execute JS by C#
Using that code I put together a demonstration of how to parse and invoke Javascript from a .NET app, using IActiveScript.
You can download a VS2010 project for this app here.

Categories

Resources