473,288 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

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.
Jul 6 '07 #1
6 4944
ak1dnar
1,584 Expert 1GB
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!
Jul 6 '07 #2
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.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.print.Doc;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.util.*;

public class RstoXml {

ArrayList al_conc = new ArrayList();
ResultSet rs = null;
public RstoXml() {
}
public static Document toDocument(ResultSet rs)throws ParserConfigurationException, SQLException{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();


Element root = doc.createElement("Concept");
doc.appendChild(root);

ResultSetMetaData rsmd = rs.getMetaData();
int col_count = rsmd.getColumnCount();

for(int i=0;i<col_count;i++){
Element Selement = doc.createElement("concept"+i);
Object obj = rs.getObject(1);
Selement.appendChild(doc.createTextNode(obj.toStri ng()));
root.appendChild(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.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

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.createStatement();
rs = stat.executeQuery(qry);
while(rs.next()) {
conc_list.add(rs.getString(1));
}
doc= RstoXml.toDocument(rs);
} catch (SQLException ex) {
ex.printStackTrace();
}catch (ParserConfigurationException pce) {
pce.printStackTrace();
}
return doc;

}
}


Here is the servelet code from here I need to pass the DOM object to client side.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
System.out.println("HaiHello");

request.getParameterValues("slt_concept");
doc = qp.PopulateConcept();
Jul 7 '07 #3
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.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.print.Doc;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.util.*;

public class RstoXml {

ArrayList al_conc = new ArrayList();
ResultSet rs = null;
public RstoXml() {
}
public static Document toDocument(ResultSet rs)throws ParserConfigurationException, SQLException{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();


Element root = doc.createElement("Concept");
doc.appendChild(root);

ResultSetMetaData rsmd = rs.getMetaData();
int col_count = rsmd.getColumnCount();

for(int i=0;i<col_count;i++){
Element Selement = doc.createElement("concept"+i);
Object obj = rs.getObject(1);
Selement.appendChild(doc.createTextNode(obj.toStri ng()));
root.appendChild(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.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

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.createStatement();
rs = stat.executeQuery(qry);
while(rs.next()) {
conc_list.add(rs.getString(1));
}
doc= RstoXml.toDocument(rs);
} catch (SQLException ex) {
ex.printStackTrace();
}catch (ParserConfigurationException pce) {
pce.printStackTrace();
}
return doc;

}
}


Here is the servelet code from here I need to pass the DOM object to client side.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
System.out.println("HaiHello");

request.getParameterValues("slt_concept");
doc = qp.PopulateConcept();

------------------------------*********************-------------------------------------------------------


Here is the Ajax part code:

<script>
function body_onload(){
createHttpRequest();

}
var request;
var url="/BudgetAmount/Mypackage/controllerservlet";
var bool=true;
var reqtype="Get";
var ref_val;

function createHttpRequest(){
if(window.XmlHttpRequest){
request = new XMLHttpRequest();
initRequest(reqtype,url,bool);
return false;
}
else if(window.ActiveXObject){
request = new ActiveXObject("Msxml2.XMLHTTP");

if(!request)
request = new ActiveXObject("Microsoft.XMLHTTP");

if(request){
initRequest(reqtype,url,bool);
}else
alert("error on Page");

}
return false;
}
function initRequest(reqtype,url,bool){
request.onreadystatechange = handleResponse;
request.open(reqtype,url,bool);
request.send(null);
return false;
}
function handleResponse(){
if(request.readystate==4 && request.status==200){
parseMessage(request.responseXML);
}
return false;
}
function parseMessage(doc){
var elements = doc.documentElement;
if(elements.hasChildNodes() && elements!=null){
var concept_names = elements.childNodes;
for(var i=0;i<concept_names.length;i++){
document.all("slt_concept").options[i+1].text=concept_names[i].nodevalue;
}
}
else

return false;
}
</script>
Jul 7 '07 #4
praveen2gupta
201 100+
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.
Jul 7 '07 #5
bartonc
6,596 Expert 4TB
Sorry, guys. I moved this here without check the OP's history first.
My bad.
Jul 7 '07 #6
acoder
16,027 Expert Mod 8TB
Merged threads.
Jul 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
3
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. ...
17
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
1
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...
19
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...
1
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. ...
4
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...
3
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...
8
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.