GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 207 of 216    Print  
Auto Populate Form Fields
How to Auto Populate Form fields in HTML/JSP page with data retrieved from an Oracle Database?


  
Total Answers and Comments: 1 Last Update: February 26, 2009     Asked by: anuantony 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 25, 2009 21:44:17   #1  
sachin.jain.mca Member Since: January 2007   Contribution: 3    

RE: Auto Populate Form Fields
with the help of ajax you can easily populate form fields.

Step you need to do is
1. Make a servlet that give response in form of XML to HTML form.
2. call the servlet fron HTML with the help of XMLHttpRequest Object through javascript .
3. got and parse the XML string send by servlet and populate form field.

//dummy code
public class myServlet extends HttpServlet
{
public void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {

String inputFiled request.getParameter("InputFiledName");
//Your JDBC code or call of you Model
//create xml string
StringBuffer lsbrXMLString new StringBuffer();
lsbrXMLString.append("<root>");

lsbrXMLString.append("<InputFiledName>");
lsbrXMLString.append("value Got from Database");
lsbrXMLString.append("</InputFiledName>");
lsbrXMLString.append("</root>");
response.setContentType("text/xml;charset UTF-8");
response.setHeader("Cache-Control" "no-cache");
response.getWriter().write(lsbrXMLString.toString());
}

}

//call servlet
function getFieldValue(){
var url <servlet url>;
var req initRequest(url);
req.onreadystatechange
function() {
if (req.readyState 4) {
if (req.status 200) {
populateFormField(req.responseXML);
} else if (req.status 204){
alert('erroe');
}
}
};
req.open("GET" url true);
req.send(null);
}
//create request object
function initRequest(url) {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE true;
return new ActiveXObject("Microsoft.XMLHTTP");
}
}


//get response from servlet parse and field in folm field
function populateFormField(responseXML){

lobjroot responseXML.getElementsByTagName("root")[0];
if (lobjroot.childNodes.length < 0) {
formField.value lobjroot.getElementsByTagName("InputFiledName")[0].childNodes[0].nodeValue;
}

}










You can also use other ajax based solutions like dojo json DWR etc.

 
Is this answer useful? Yes | No

 Related Questions

View Question | Asked by : suresh

I have created one MVC architecture.But i am getting the error asHTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description 
View Question | Asked by : Sandip Kumar samantaray

In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
View Question | Asked by : b.sadhukhan

View Question | Asked by : abhayanand

View Question | Asked by : santosh Sharma

A CGI scripts is a program that is written in C,C++,or Perl.A CGI script gets executed in a server.When a aserver receives a request from the client for processing data,the server passes the request to 
View Question | Asked by : sujatham

How to Auto Populate Form fields in HTML/JSP page with data retrieved from an Oracle Database? 
Latest Answer : with the help of ajax you can easily populate form fields.Step you need to do is 1. Make a servlet that give response in form of XML to HTML form.2. call the servlet fron HTML with the help of XMLHttpRequest Object through javascript .3. got and parse ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 

JavaScript Form Object

JavaScript Form Object In this JavaScript Tutorial you will learn about JavaScript form object properties of form object action elements encoding length method name target button checkbox FileUpload hidden password radio reset select submit text textarea and methods of form object mosgoogle Form Obj
 

The Use of Access Specifiers In Object Oriented Programming

The Use of Access Specifiers In Object Oriented Programming In object oriented programming a variable will have a certain range This range can be defined as the place where it can be viewed In most cases there are two simple models that are used and these are lexically scoped and dynamically scoped
 

Class-based Object Oriented Programming

Class based Object Oriented Programming Class based object oriented programming is a style that gains inheritance by processing classes as objects The most prominent style of OOP is class based instead of object based With the class based OOP system objects are units that merge states identities and
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape