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

12,559

Solution 1

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.

Solution 2

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

Share:
12,559
ashmish2
Author by

ashmish2

Updated on June 04, 2022

Comments

  • ashmish2
    ashmish2 almost 2 years

    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

  • ashmish2
    ashmish2 almost 13 years
    so which server should i use to execute c++ code (wamp or smthing). I can change the server but the code has to be in c++