Reputation: 9959
In my JSP page I have DIV
.
<div id="100">
ALI
</div>
When I click on this DIV
...
$("#100").click(function(){
});
...I need to send the value of the id 100
, to a servlet, so that the servlet makes some database java codes, and returns for example, either 1 or 0. How can I do that? and is this the proper way?
Upvotes: 0
Views: 2556
Reputation: 3687
Using Ajax, you should call your server using a URL similar to this:
http://localhot:8080/youAppContext/yourServer?id=100
Then, in the servler side, you should retrieve the value that will be in the request with the name "id"
There are out there many tool as jQuery that can help you to do the Ajax petition.
Edited
Well, here you can find a very simple Ajax example using jQuery. In the example, instead call a file (test1.txt) you should invoke a URL (as I described above). Of course, you will need to write some JS code to build your URL (where id be a variable). Once task is done in servlet side, you can return whatever, for example: "done" and display or not this information the HTML as it is done in the example.
Take a look to this Web, there are many links that can help you.
Upvotes: 3
Reputation: 240870
get the value using
var value = $("#100").html();
and pass it to servlet using AJAX
Upvotes: 0