473,398 Members | 2,343 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,398 software developers and data experts.

Problem in Using Ajax within JSP

Is it Possible To return a xml object from a jsp file?
i tried. but i get an error. i have pasted the code & error below.

Code :
<body>
<table width="100%">
<tr>
<td>
<%
String testOne = request.getParameter("HeyYou");
response.setContentType("application/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<testValue>"+testOne+" </testValue>");
%>
</td>
</tr>
</table>
</body>

Exception :

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------

Only one top level element is allowed in an XML document. Error processing resource
Feb 22 '07 #1
4 3551
acoder
16,027 Expert Mod 8TB
If the XML is incorrect, it's not going to work. To correct your XML, ask in the XML forum. If you're using Ajax, that's client-side+server-side. You're showing the JSP.

Also, for XML, you can't put it in a table. Form a proper XML document in a JSP file, then from the client-side use an XMLHttpRequest object to request the JSP response. Finally parse the reponse text and display on the client-side.

Perhaps, you should study Ajax/XML further, see here.
Feb 22 '07 #2
Dear moderator,
thanx for the reply.
Actually i have worked with ajax. In the jsp, i 'll be writing the script that forms the xmlhttprequest object, and i 'll call a url wich corressponds to java code, where i 'll do my server side activities and then return it to jsp as a xml object. and in the jsp again i 'll parse the responseXML and i'll put it in the form.

But for the application, which i'm trying now is to
i'm passing a jsp file as a url in ajax in a jsp file SampleJsp.jsp.
ex:
var url = "myjsp.jsp?myCode=1";
req.open("GET",url, true);

And in myjsp.jsp,
i'm using the javacode in myjsp.jsp file to return a xmlresponse
ex:
response.setContentType("html/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<testValue>"+request.g etParameter("myCode")+"</testValue>");

Now, im trying to parse the responseXML in SampleJsp.jsp
ex:
var responseValue = responseXML.getElementsByTagName("testValue")[0];

The problem is i'm getting a responseValue as a null object.
My doubt is whether a jsp can return a responseXML .
Feb 22 '07 #3
acoder
16,027 Expert Mod 8TB
The problem is i'm getting a responseValue as a null object.
My doubt is whether a jsp can return a responseXML .
For that, you'll have to ask in the Java forum. All JSP questions are answered in the Java forum.

Why don't you try a simple response first? If that works then you can build on it. If you've already done this, then you need to find out about JSP and XML, but I think it should be able to do it.

Also, one last thing, don't forget that you should add:
Expand|Select|Wrap|Line Numbers
  1. req.send(null);
when making the request to the server. Also, you should have an onreadystatechange event handler for the Ajax to work.
Feb 22 '07 #4
Dear Moderator,

Thanx again for replying.

Now i have figured that the problem is in returing a xml object from another jsp file instead of java file. And there is no problem with implementing ajax, coz i'm getting a response object. but it is null.

As per ur suggestion,I 'll post my question in jsp or java group.

- Jagadesh
Feb 23 '07 #5

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

Similar topics

12
by: nat | last post by:
Hi all, I was going to post this in the AJAX forum, but apparently someone posted an AJAX/C# question in there today and was told to try this forum instead. So here goes: I'm trying to figure...
7
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
5
by: noddy | last post by:
The full code relating to this question can be found at http://marc.info/?l=php-general&m=112198633625636&w=2 It describes a bare bones way of making an AJAX request. It works fine for me except...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: Victor | last post by:
Hi guys, I have a very strange problem with scriptmanager here. I want to load a js (which is embed in the project) but everytime i try to load that, it gives me error like Specified argument was...
0
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two...
5
RamananKalirajan
by: RamananKalirajan | last post by:
Hi those who were working in Ajax, will surely experienced with this problem. SOP - Single Origin Policy problem. I am doing a small work in Prototype Ajax. I did a sample work. When I am passing the...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
8
by: Tomasz J | last post by:
Hello developers, After migrating my web project application (using the old model) to .Net Framework 3.5 and Ajax Control Toolkit release 20820 the Accordion control no longer works correctly....
1
by: Constantine AI | last post by:
Here is the situation i am currently trying to update a sales order using PHP and javascript. When you click on the edit button it brings you a new site page with existing sales order details within....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.