Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can i use servlets to deploy a JNI application  RSS feed

 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Hope this is the right place for this post.

I have a c++ code which does some basic database operations. I have written a JNI wrapper for this code.

Now i need to deploy this on a apache(Web server) so i can send requests from a client (http://localhost:8080/MyApp/update.do?type=1&num=2) and be able to execute the wrapper.

Is this the right approach?

Can this be done? I have decided to use servlets for this.

Also If anyone has tried this before has heard of this being done can you please detail me with the procedure for the same.

Gaurav
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up MVC Model, View, Controller.

The whole point of this architecture is to isolate your core functionality (the model) from the web aspects of your app. If done correctly, your web app should not know or care that you're using JNI to accomplish something. It only know that it calls bean x, y, or z to perform a given task.
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Thanks for the reply....
So the Model part (in MVC) would be the JNI wrapper..... or will there be a call to the JNI wrapper from the model....

I mean shall controller be calling the JNI directly or will there be a call to a model module which will in turn call the JNI part...

Regards,
Gaurav
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could work either way.

As a general rule I try to code my model beans to work from the command line.
This way, they can be tested without the need of a servlet container.
Once they are running as standalone Java classes, I write the servlets and JSPs that use them.

As an example, with JDBC databases, my rule of thumb is that I don't import any javax.servlet classes in the model beans and I don't import any jdbc classes in the servlets. I also avoid having any helper classes that import both. It's an oversimplification but it's worked for me.
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thats a great suggestion... will do that..
Thanks..
Gaurav
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!