Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Verifing User Input

 
Ranch Hand
Posts: 2025
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaScript technology to make requests to the server is called Ajax. This article is a good place to start.
 
Steve Dyke
Ranch Hand
Posts: 2025
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2025
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2025
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 2025
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone give me syntax example for posting to servlet from AJAX?
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic