Member Avatar

Hi,

I'm starting to learn Ajax after playing around with JSP and Javascript, I felt the need for interaction without reloading the page.

I've searched everywhere for a simple java servlet/ajax example that I can play around with but just found a lot of asp and complex java examples.

Could someone please give me something as basic as typing a name in a text field and text being displayed beneath the text field after the word/letter has been typed. i.e. User must enter a name that is 3 or more letters else the text says "Error".

I'm currently using Netbeans, so if the example could work there, that wold be preferable!

Thanks a lot,
-Ashton.

Recommended Answers

The example you described isn't AJAX, that's just standard Javascript validation. AJAX would be, for example, as the user types display a list of possible selections underneath the box.

http://w3schools.com/ajax/ajax_intro.asp

Jump to Post

Don't be silly... you know very well that it could be done with Ajax.

Sure, it COULD be done with AJAX but there is absolutely no reason to. The term/acronym AJAX describes making a request to the server then receiving and parsing XML. There is absolutely, positively no reason to …

Jump to Post

It isn't a Netbeans project but it is a JSP AJAX primer (found by searching AJAX JSP on google...) http://www.ics.uci.edu/~cs122b/projects/project5/AJAX-JSPExample.html

It should also be noted that while it is very important that you are familiar with your IDE it's just as important to not become absolutely dependent …

Jump to Post

All 11 Replies

The example you described isn't AJAX, that's just standard Javascript validation. AJAX would be, for example, as the user types display a list of possible selections underneath the box.

http://w3schools.com/ajax/ajax_intro.asp

Member Avatar

Don't be silly... you know very well that it could be done with Ajax.

Don't be silly... you know very well that it could be done with Ajax.

Sure, it COULD be done with AJAX but there is absolutely no reason to. The term/acronym AJAX describes making a request to the server then receiving and parsing XML. There is absolutely, positively no reason to do something so complex for validation.

Member Avatar

I said that I'm starting to learn it... I just want to view how ajax works altogether in action to see how it allows requests/responses without reloading a page. I want to see how it runs a servlet without reloading the page. In the most basic form possible. Preferably on a Netbeans project. I've read a couple of tutorials and w3schools and so on, but I want to play around with it on Netbeans.

It isn't a Netbeans project but it is a JSP AJAX primer (found by searching AJAX JSP on google...) http://www.ics.uci.edu/~cs122b/projects/project5/AJAX-JSPExample.html

It should also be noted that while it is very important that you are familiar with your IDE it's just as important to not become absolutely dependent upon it.

Member Avatar

Thanks, but that doesn't really help. I've also found lots of casual ajax examples. They don't work on Netbeans though...

Try these two links, I havent tried them, but they seem to be pretty good
http://www.devarticles.com/c/a/Java/J2EE-and-AJAX-AJAX-with-Servlets/

http://www.java-tips.org/java-ee-tips/enterprise-java-beans/using-ajax-with-java-technology.html

There are also loads of examples out there, you just have to search for them.

When i first started learning jsp, I came across a lot of examples that were incomplete, dont be discouraged though, just try solving them yourself, google helps a lot, a lot of the errors are newbie errors. but you will get the hang of it.

Member Avatar

Thanks... I've already done the drop down list example and got it to work on Netbeans... It's a bit complicated though, I want something simple like the example I explained initially...

Member Avatar

Hi,

I found an easy Ajax example here:
http://www.w3schools.com/Ajax/ajax_serverscript.asp

It also contains a demo of the end product.

The only problem is that it requires a "time.asp" but does not contain much information on how to do that. I come from a JSP background and don't know anything at all about asp... Would it be possible to translate the code snippet they gave to JSP? Below is the asp code I need to translate to JSP:

<%
response.expires=-1
response.write(time)
%>

Thanks,
-Ashton.

Member Avatar

*Deleted*

Member Avatar

Here is the servlet Version:

out.println(time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());

Then just add the following code to your Javascript on the JSP:

function init(){
                window.setInterval("ajaxFunction()",1000);
            }

And call it here:

<body onload="init();">

This will run a function every 1000ms.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.