Home

Spacebug open source initiative

Primary links

  • Get involved
Home Blogs Amir Shevat's blog

Navigation

  • Documentation
  • Projects
    • Ajaxdo
    • JComet
    • MantaRay
    • Spring-Dashboard
    • JNI.NET
  • Blogs
  • Downloads

Tag cloud

Architecture Ant Drupal eclipse JSP .NET Reviews JavaScript AJAX Tips Open source Java
more tags


Add to Google Reader or Homepage

Poll

Best for web dev:

Recent blog posts

  • Useful tool - Vista Battery Saver
  • Does the open source professional services business model suck?
  • PHP calling .NET - PHP to WCF calls with parameters
  • Adding Spacebug to Technorati.
  • PHP calling .NET - PHP to WCF communication
  • Language syntax's, performance, PHP, Ruby, Java and who's better? Ahhhh!
  • Does Google want us to switch from Internet Explorer to Firefox?
  • PHP calling .NET - Running WCF service with basicHttpBinding
  • Tip: Visual Studio 2008 fails to debug WCF web service
  • I love my MVC ...
more

User login

  • Create new account
  • Request new password

Tip: how to write an XML document with JSP for AJAX applications

Submitted by Amir Shevat on Fri, 07/18/2008 - 11:28
  • AJAX
  • Java
  • JavaScript
  • JSP
  • Tips

AJAX applications usually connect to a server side application and request data in the form of XML. When the server side is written in JSP (Java Server Pages), for example a spring-framework web application with JSP views, writing the XML response is sometimes problematic.
The problem:
When using JSP to format the data in to XML and send it to the AJAX application, the XML is not recognized as XML (empty DOM object) and the AJAX application does not function properly.
The solution:
Add this to the beginning of the JSP
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("pragma","no-cache");

%>
In addition, make sure there are no spaces between this addition and the root tag of the XML in the JSP, these spaces might create the same problem.
An example of this AJAX-JSP communication can be found in the Spring-dashboard code under the examples folder in this release (files: monitorData.jsp and monitor.jsp)

  • Amir Shevat's blog

Post new comment

Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

Powered by Drupal, an open source content management system
Spacebug.com (c)2006
RoopleTheme