How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax.
kindly advice me.
6 4982 ak1dnar 1,584
Recognized Expert Top Contributor
Its Better to ask this question with the Coding that you made so far.
Because the coding might explain the situation rather than 1000 words that you've posted with your question. Thanks!
Post: how to request to servlet from Ajax
--------------------------------------------------------------------------------
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax.
Kindly advice me.
Re: how to request to servlet from Ajax
--------------------------------------------------------------------------------
Its Better to ask this question with the Coding that you made so far.
Because the coding might explain the situation rather than 1000 words that you've posted with your question. Thanks!
*************** *************** *************** *************** *************** *************** *************** *************** *************** *************** *************** *************** ****
Here is the Buss Logic Code from which i am getting DOM Object
package Mypackage;
import java.io.IOExcep tion;
import java.io.StringR eader;
import java.io.StringW riter;
import java.sql.Result Set;
import java.sql.Result SetMetaData;
import java.sql.SQLExc eption;
import javax.print.Doc ;
import javax.xml.parse rs.DocumentBuil der;
import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.parse rs.FactoryConfi gurationError;
import javax.xml.parse rs.ParserConfig urationExceptio n;
import org.apache.xml. serialize.Outpu tFormat;
import org.apache.xml. serialize.XMLSe rializer;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;
import org.xml.sax.Inp utSource;
import org.xml.sax.SAX Exception;
import java.util.*;
public class RstoXml {
ArrayList al_conc = new ArrayList();
ResultSet rs = null;
public RstoXml() {
}
public static Document toDocument(Resu ltSet rs)throws ParserConfigura tionException, SQLException{
DocumentBuilder Factory factory = DocumentBuilder Factory.newInst ance();
DocumentBuilder builder = factory.newDocu mentBuilder();
Document doc = builder.newDocu ment();
Element root = doc.createEleme nt("Concept");
doc.appendChild (root);
ResultSetMetaDa ta rsmd = rs.getMetaData( );
int col_count = rsmd.getColumnC ount();
for(int i=0;i<col_count ;i++){
Element Selement = doc.createEleme nt("concept"+i) ;
Object obj = rs.getObject(1) ;
Selement.append Child(doc.creat eTextNode(obj.t oString()));
root.appendChil d(Selement);
}
return doc;
}
}
Here is the another Buss Logic from here i am passing the DOM object to servlet
import Mypackage.*;
import java.util.*;
import java.sql.*;
import javax.xml.parse rs.ParserConfig urationExceptio n;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;
public class QueryPopulate {
Connection con=null;
Statement stat=null;
ResultSet rs =null;
Document doc = null;
dbaseconnection dbase = new dbaseconnection ();
ArrayList conc_list = new ArrayList();
RstoXml xl;
/** Creates a new instance of QueryPopulate */
public QueryPopulate() {
}
public Document PopulateConcept (){
String qry = "select distinct ConceptName from Concept";
con = dbase.getconobj ();
try {
stat = con.createState ment();
rs = stat.executeQue ry(qry);
while(rs.next() ) {
conc_list.add(r s.getString(1)) ;
}
doc= RstoXml.toDocum ent(rs);
} catch (SQLException ex) {
ex.printStackTr ace();
}catch (ParserConfigur ationException pce) {
pce.printStackT race();
}
return doc;
}
}
Here is the servelet code from here I need to pass the DOM object to client side.
protected void processRequest( HttpServletRequ est request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
System.out.prin tln("HaiHello") ;
request.getPara meterValues("sl t_concept");
doc = qp.PopulateConc ept();
Re: how to request to servlet from Ajax
Post: how to request to servlet from Ajax
--------------------------------------------------------------------------------
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax.
Kindly advice me.
Re: how to request to servlet from Ajax
--------------------------------------------------------------------------------
Its Better to ask this question with the Coding that you made so far.
Because the coding might explain the situation rather than 1000 words that you've posted with your question. Thanks!
*************** *************** *************** ***** *************** *************** *************** ***** *************** *************** *************** ***** *************** *************** ****
Here is the Buss Logic Code from which i am getting DOM Object
package Mypackage;
import java.io.IOExcep tion;
import java.io.StringR eader;
import java.io.StringW riter;
import java.sql.Result Set;
import java.sql.Result SetMetaData;
import java.sql.SQLExc eption;
import javax.print.Doc ;
import javax.xml.parse rs.DocumentBuil der;
import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.parse rs.FactoryConfi gurationError;
import javax.xml.parse rs.ParserConfig urationExceptio n;
import org.apache.xml. serialize.Outpu tFormat;
import org.apache.xml. serialize.XMLSe rializer;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;
import org.xml.sax.Inp utSource;
import org.xml.sax.SAX Exception;
import java.util.*;
public class RstoXml {
ArrayList al_conc = new ArrayList();
ResultSet rs = null;
public RstoXml() {
}
public static Document toDocument(Resu ltSet rs)throws ParserConfigura tionException, SQLException{
DocumentBuilder Factory factory = DocumentBuilder Factory.newInst ance();
DocumentBuilder builder = factory.newDocu mentBuilder();
Document doc = builder.newDocu ment();
Element root = doc.createEleme nt("Concept");
doc.appendChild (root);
ResultSetMetaDa ta rsmd = rs.getMetaData( );
int col_count = rsmd.getColumnC ount();
for(int i=0;i<col_count ;i++){
Element Selement = doc.createEleme nt("concept"+i) ;
Object obj = rs.getObject(1) ;
Selement.append Child(doc.creat eTextNode(obj.t oStri ng()));
root.appendChil d(Selement);
}
return doc;
}
}
Here is the another Buss Logic from here i am passing the DOM object to servlet
import Mypackage.*;
import java.util.*;
import java.sql.*;
import javax.xml.parse rs.ParserConfig urationExceptio n;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;
public class QueryPopulate {
Connection con=null;
Statement stat=null;
ResultSet rs =null;
Document doc = null;
dbaseconnection dbase = new dbaseconnection ();
ArrayList conc_list = new ArrayList();
RstoXml xl;
/** Creates a new instance of QueryPopulate */
public QueryPopulate() {
}
public Document PopulateConcept (){
String qry = "select distinct ConceptName from Concept";
con = dbase.getconobj ();
try {
stat = con.createState ment();
rs = stat.executeQue ry(qry);
while(rs.next() ) {
conc_list.add(r s.getString(1)) ;
}
doc= RstoXml.toDocum ent(rs);
} catch (SQLException ex) {
ex.printStackTr ace();
}catch (ParserConfigur ationException pce) {
pce.printStackT race();
}
return doc;
}
}
Here is the servelet code from here I need to pass the DOM object to client side.
protected void processRequest( HttpServletRequ est request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
System.out.prin tln("HaiHello") ;
request.getPara meterValues("sl t_concept");
doc = qp.PopulateConc ept();
------------------------------*************** ******-------------------------------------------------------
Here is the Ajax part code:
<script>
function body_onload(){
createHttpReque st();
}
var request;
var url="/BudgetAmount/Mypackage/controllerservl et";
var bool=true;
var reqtype="Get";
var ref_val;
function createHttpReque st(){
if(window.XmlHt tpRequest){
request = new XMLHttpRequest( );
initRequest(req type,url,bool);
return false;
}
else if(window.Activ eXObject){
request = new ActiveXObject(" Msxml2.XMLHTTP" );
if(!request)
request = new ActiveXObject(" Microsoft.XMLHT TP");
if(request){
initRequest(req type,url,bool);
}else
alert("error on Page");
}
return false;
}
function initRequest(req type,url,bool){
request.onready statechange = handleResponse;
request.open(re qtype,url,bool) ;
request.send(nu ll);
return false;
}
function handleResponse( ){
if(request.read ystate==4 && request.status= =200){
parseMessage(re quest.responseX ML);
}
return false;
}
function parseMessage(do c){
var elements = doc.documentEle ment;
if(elements.has ChildNodes() && elements!=null) {
var concept_names = elements.childN odes;
for(var i=0;i<concept_n ames.length;i++ ){
document.all("s lt_concept").op tions[i+1].text=concept_n ames[i].nodevalue;
}
}
else
return false;
}
</script>
Its Better to ask this question with the Coding that you made so far.
Because the coding might explain the situation rather than 1000 words that you've posted with your question. Thanks!
Hi
I have ssen your coding. You have not applied Ajax till now. Steps that can help you with java/jsp use.
1. Ajax works with browser. So make a proper file prefers jsp. So that you can
Interact with browser.
2. Through Ajax you should call jsp page, This jsp page can interact with the java classes and servlets.
3. Direct applying ajax to the servlets , I think not possible.
bartonc 6,596
Recognized Expert Expert
Sorry, guys. I moved this here without check the OP's history first.
My bad.
acoder 16,027
Recognized Expert Moderator MVP Sign in to post your reply or Sign up for a free account.
Similar topics |
by: efiedler |
last post by:
Hi - I have the following input field on my html page:
<input type="image" name="submit" id="submit" src="c:\image.jpg"
value="image.jpg">
I also have another input field on the form that is a text box. When
submitted my form posts its data to a servlet. I can click on the
image, and the form is posted and the servlet is ran. However, I was
stepping through the debuger of the servlet and I noticed the request
|
by: ppcguy |
last post by:
i've got a progress bar that tracks a process running on
a server (java servlet).
i know i can refresh the page and update the status...but
this results in the page being redrawn everytime.
is there a way i can call a servlet from javascript and
process the results directly - and in this case get the
percent done and then update the progress bar.
|
by: petermichaux |
last post by:
Hi,
Is it possible for an AJAX request to be left open for multiple
responses? This could avoid repetitive polling of the server.
Thanks,
Peter
|
by: smartestdesign |
last post by:
I am trying to send request using ajax with some japanese text.
As any of you know XMLHttpRequest is send with utf-8.
I was hoping there is a way to send with different encoding like
var parameters = "metadata=" +
encodeURI(document.getElementById("metadata").value);
http_request.onreadystatechange = metadataUpdate;
http_request.open( 'POST', "/servlet/SendJapText", true );
|
by: roh |
last post by:
Hi Folks,
We have e-Biz application running on WebSphere Application Server Ver 6.0 using DB2 UDB Ver 8.1 . We are facing following issue in our application , any help from your side will be highly appreciated.
Issue:
========================================================
Sometimes while browseing through the web pages we are facing following error.
“We're sorry but the request could not be processed.The processing error message...
| |
by: Vimala Sri |
last post by:
Hello all,
Have a great day. I wish to made interaction from c program in unix to the java servlet. That is i want to send a request from the Unix c program to the servlet.
I have no idea on how to do this?
The exact scenario is In the client there is a c program which send a request to the server (servlet in java) using poat method and should the response from the servlet.
The...
|
by: spargos |
last post by:
I'm having significant trouble getting the scriptalicious or dojo toolkits to work for me. For instance I'm trying to implement a simple blinddown in my page. If I were to do this:
<div id="listDiv" onclick="new Effect.BlindDown(this)">Show My Hidden Data</div>
it will work.
However if I try to move the effect like so:
<script type="text/javascript" language="javascript">
window.onload=function() {
|
by: vijaykumardahiya |
last post by:
Dear Sir,
I have two queries.
First question is:
I have a Html page. On which Have two buttons Submit and Issue.
I want when I click on Sumit button request should be go to submit.jsp. and When I click on Issue button then request should be go to Issue.jsp.But When I click on submit button request do to Issue.jsp.
Second Question is How I reterive the input parameter of html page to submit.jsp.
Please review..
My files are:
login.html:
|
by: webster5u |
last post by:
I'm design MVC structure for current developing system.
Initially, the jsp will post data to servlet class. After processing, servlet will use the requestDispatcher to return processed data back to jsp.
RequestDispatcher dispatcher = request.getRequestDispatcher("/webapps/hrd/test.jsp");
dispatcher.forward(request,response);
Now, the process the successful but i found the url display on address bar still remain as servlet url. It cannot...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |