Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute c++ code at server side using tomcat server?

I am a beginner in writing web application, so please co-operate if its a silly question. Our web application is hosted using tomcat 6. I have some C++ code to be executed in server when user click on corresponding button. Client side is written in html/JS and hosted using tomcat.

So, My problem is I dont know how this C++ code will be executed when a button is clicked in html page. Can anyone please help me?
[updated]
I can change from tomcat to any other server but code has to be in c++. So if you have any other server(wamp or smthing) or links to do the same. Please let me know

like image 750
ashmish2 Avatar asked Feb 23 '23 19:02

ashmish2


2 Answers

Tomcat, a Java Servlet container is definitely not the most appropriate vehicle to execute C++ code in. You could try to use JNI to make a servlet run the C++ code, but it seems to me that there are much easier and reliable ways, like good old CGI's. Tomcat can do CGI, as explained here, with some limitations and restrictions.

Update: I think we can agree that the CGI route is the way to go. Most webservers allow you to run cgi's, and it will definitely be simpler than with Tomcat. I also suggest you delegate the work of connecting your code to the web server to a library, like gnu cgicc (nice tutorial here) or cgic. A plain old WAMP (you'll just use the WA part here) and that sample code should get you up to speed in no time. The rest will be pretty standard Web development.

like image 158
fvu Avatar answered Mar 05 '23 15:03

fvu


https://stackoverflow.com/questions/175507/c-c-web-server-library answers may well help you out.

Given that Tomcat is no longer a requirement, using a different http front end may well make your life easier.

If you do decide to use Tomcat Which C++ Library for CGI Programming? may help you pick a library.

Barring that, if you use Apache, you can write a plugin module itself, instead of CGI, which will give you much better performance. (Other web servers generally have similar plug-in methodologies also...)

Good Luck

like image 33
sdg Avatar answered Mar 05 '23 17:03

sdg