How can I embed XML code in my JSP? Where can I give a link to my XSL file?

Renato Michielin

To generate XML set the contentType of the page to text/xml:

<?xml version="1.0" ?>
<%@ page contentType="text/xml" %>

(Put the page directive on the second line, otherwise the compiler leaves a blank first-line and this may cause an error when XML document is parsed).
You may link to an XSL style sheet from the page inserting an xml-stylesheet processing-instruction after the xml declaration:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="myxsl.xsl" ?>
<%@ page contentType="text/xml" %>
To code XML dynamically, add a bean to the page and call a method to populate an element:
<jsp:useBean id="mybean" class="mypackage.myclass" />
<mytag><%= mybean.getSomeValue() %></mytag>
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.