How to compare the datas from Website with Database - java

I have one scenario i.e., need to compare the values from Website with Database(MS Sql Table Values)
In my website having one datatable which is dynamic and the values changed based on Username.
I need to check whether the values present in datatable(website) should match with the Database.
Kindly let me know any ideas and code snippet for this.

You can use Javascript/Jquery that when a user change a value in datatable send a Ajax asyncron request to the java server and here check the values.
For example:
$( ".target" ).change(function() {
$.ajax({
type: 'POST',
url: 'myUrl',
data: JSON.stringify(myValues),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
})
});

Possibly I would load the data from MySQL -> Put it in Some POJO that mimics my datatable -> And preValidate the data -> put it in datatable.
Please put out some code which you have tried already.

Related

How send information from forms without submit modal?

Right now i'm using jsp and bootstrap to make my front-end, and i have an option to make a new register inside a modal and this new register needs to be in my behind screen, in the past projects I used angular and it was very easy to do, but now using jsp I haven't any ideia to make it without submit my modal.
Is there a way to make it without submit my modal?
You can use Ajax, that way you can post the form to back-end to make what you need to do and than return the object to front-end.
Seeing your tags you're be able to make like that
Controller:
#Post
public void methodName(final T entity) {
.
.
.
result.use(Results.json()).withoutRoot().from(insertedObject).serialize();
}
Front:
$.ajax({
type : 'POST',
url : 'method url',
data : form.serialize(),
success : function(data){
// data is the object inserted
}
});

How to send Ajax requests in Java

Is there a way to send ajax requests in a Java program? I was thinking that there might be a jquery library somewhere, but I don't even know if jquery would be something that I should use. I'm trying to get the data from a certain request from a website as shown in this function:
function searchFraze(fraze, page) {
page = typeof page !== 'undefined' ? page : 1;
$.ajax({
url: 'ajax/tradeCsRight.php',
type: 'POST',
data: "search=1&type=10&fraze="+fraze+"&page="+page,
success: function(data) {
$("#itemlist").html(data);
}
});
}
Basically, I want to POST custom data in the data field above to the website (http://csgolounge.com/). Honestly, I don't even know if I should be doing what I'm doing this way, or if I should use some other method.
Also, in FireBug, I can see the contents of the tradeCsRight.php file as seen here (which is my goal, to see the html content of this): http://i.imgur.com/8ACnGbp.png
If I open the actual file in chrome, however, the page and html is blank (http://i.imgur.com/LHtKyUb.png). Can someone tell me why this is?

Create an AJAX Overlay with text

I am wanting to use AJAX to create a screen area that overlays on the current window. An example of one of these is like those adverts that don't open in a new window or when you are on reddit and try and vote on a post without being logged in. I can't find any documentation on such a thing. Does anyone know how to do this?
I'm not very much clear what you are asking.But What I undestood is , you want an overlay when ajax request is sent.
So, the solution for that is below .
In Html :
With Jquery :
$.ajax({
url: "#Url.Action("GetMyCandidate")",
contentType: "application/json; charset=utf-8",
dataType: "json",// your type
beforeSend: function () {
// show your overlay div
$("#overlay").show();
}
}).success(function (data) {
$("#overlay").hide();
// your futher code
});

Parsing with Jsoup, only gets default value

I'm parsing a webpage with Jsoup which so far is going good, except that when I parse, I get the data that's the 'default text', the text displayed right before a javascript changes the value.
There's
<span id="p1name" class="redtext">Player 1</span>
which I can parse with
Element player1Div = doc.getElementById("p1name");
p1name = player1Div.text();
player1.setText(p1name);
Then there's a script on the website
<script>
$(document).ready(function() {
getData();
});
function getData() {
$.ajax({
type: 'get',
url: '../data.json',
data: '',
dataType: "json",
success: function(data) {
player1name = data['p1name'];
$("#p1name").text(player1name);
</script>
which changes the element's text. So I thought I could just run the java code again and get the new text, but that won't work as I keep getting "Player 1" (whereas I'm sure it should display a different string)
What are my options? How do I solve this?
JSoup can't solve your problem. All Jsoup knows is parse and extract the data.
As the desired text is not part of the html during the parsing it can't be extracted from the Document
All you can do is, issue a new request to ../data.json and fetch the data. Provided, you know that url before fetching the content.

How to use request/session attribute after jquery ajax request?

I have a form (comform) sent with this jquery ajax methode :
$(document).ready(OnReady);
function OnReady(){
$('#comform').submit(onComm);
}
function onComm(data){
$.ajax({
type: $(this).attr("method"),
url: $(this).attr("action"),
data: $(this).serialize(),
success: newComment('${cid}')
});
return false;
}
Inside the servlet's code I do this :
request.setAttribute("cid", methode());
(for short, the servlet use the form inputs' values to fill a table in my DB then I retrieve the id of this insert, put it as attribute as shown above and that's it !)
But even if I set 'cid' in the session scope, I give an empty string to 'newComment' instead of the int that 'methode()' actually return.. In fact, the ${cid} element in not refresh..
What can I do to get this attribute without reload the page ?
How can I use some result datas ?
Thanks

Categories