0

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.

3
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by AshtonHogan
0

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.

0

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.

0

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

0

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.

0

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...

0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.