my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Verifing User Input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Verifing User Input" Watch "Verifing User Input" New topic
Author

Verifing User Input

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
In my app a user is required to type in a job number. I need the job number verified before the form is submitted. The job number data resides on an AS400 database. Would I use javascript to connect to AS400 database? Or would I have javascript call a java class that makes the connection.

In my app I presently have several classes that make connections and pull various other data.

My problem is I don't know how to write javascript to make a connection nor how to call an existing java class if either of these is the solution to my problem.

Thanks for helping.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60762
    
  65

The JavaScript technology to make requests to the server is called Ajax. This article is a good place to start.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
What about using the JSP plug in. However, when I try this I get a Broken Link message on my HTML page.

My Code is:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60762
    
  65

I suppose you could somehow mangle an applet to make this work. If that's what you want to do, let me know and I'll transfer this post to the appropriate forum.

That's not a course of action I'd advise, however.

Also, please familiarize yourself with the "disable smilies" checkbox on the entry page when posting code.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
I have looked at the AJAX as you suggested and done some simple tasks. Can you help with the more complicated issue of a connection and executing a SQL statement to return a result?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60762
    
  65

All of that has nothing to do with Ajax. Once the request has been submitted to a server-side resource, that can do whatever it needs to access the database. What are you using for server-side code? Servlets? php?

Result data can be returned as the response in any form you would like. XML and JSON are most popular, with the latter beinf the easiest to deal with in JavaScript code.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
Since I am a little familar with java servlets and I know how to use them to create java objects and I already have java objects that make necessary connections, can I just use AJAX to call a servlet which can create a session attribute and then use the attribute on my calling form. I really apologize for my lack of understanding. Every day I learn more thanks again.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Steve Dyke:
can I just use AJAX to call a servlet which can create a session attribute and then use the attribute on my calling form.
Well, sort of. Sure, you can call the servlet via AJAX. (Actually what you really do is to send a request for the servlet.) And sure, that servlet can put attributes into the session and get attributes from the session. Servlets can do that. But servlets return text to your browser. HTML, most likely. Or perhaps XML or some other format, but whatever you want to return, you have to format as text. Normally that isn't a problem at all.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

html->javascript->ajax->servlet/controller->data access object->database

That's pretty much the the flow, so, from your web page use javascript to make an ajax call to your servlet or controller which accesses a data access object (DAO) which gets your data from the database. Then return this through your controller to javascript and deal with response to update your HTML however you see fit.


GenRocket - Experts at Building Test Data
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
Can someone give me syntax example for posting to servlet from AJAX?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60762
    
  65

Do you mean the URL? It's be the same as the URL from a link you'd create to the servlet, or to invoke the servlet from the address bar.

If you are talking about code, the article I linked to explains the API.

That said, I'd not do Ajax calls directly. It's much easier to use the simplified API's provided by JavaScript libraries such as Prototype or jQuery.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Verifing User Input
 
Similar Threads
AS400 ToolBox Question
Using AS400JDBCDriver() and AS400() together
Send parameter using XMLHttpRequest
AS400ConnectionPool class question (IBM toolbox)
Regarding Web Faced Application...