Mixing XML syntax w/JSP syntax

As I understand it, you can use either the JSP-specific syntax or an XML-based syntax for code in a JSP page. For instance you can use either
  <%= expresssion %>(JSP-specific syntax)
or
  <jsp:expression>
    expression
  </jsp:expression>(XML-based syntax)
to do much the same thing. But I think once I heard somewhere that the two syntaxes cannot be mixed on the same JSP page. Two questions about that:
(1) Is it true?
(2) If it is true, what about a page of one syntax that includes (using include directive) a page of the other syntax -- there will be inconsistency here.
Thanks if you can answer this.

A jsp source file(.jsp) should be in either Xml syntax or Jsp syntax.

Similar Messages

  • XML syntax error in a JSP page.

    Hi,
    i was trying to include xml syntax in a jsp page in stead of core jsp syntax. it didn't work.But the jsp document with the core jsp syntax works. I'm wondering what's the problem.any help would be really helpful. I'm using Tomcat 3.2.1.
    Thanx in adv,
    Ganesh
    JSP file - NOT WORKING
    <jsp:directive.page import="java.util.Date"/>
    <jsp:declaration>
    private static String loadTime = new Date().toString();
    private static String getLoadTime() { return loadTime; }
    private static String getCurrentTime() { return new Date().toString(); }
    </jsp:declaration>
    <HTML>
    <HEAD><TITLE>XML and JSP</TITLE></HEAD>
    <BODY>
    JSP page is created using XML syntax...<BR>
    This page was loaded into memory at <%= getLoadTime() %>.<BR>
    The current time is <%= getCurrentTime() %>
    </BODY>
    </HTML>
    ERROR :
    Error: 500
    Location: /test/declarations.jsp
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat321\tomcat\work\localhost_8080%2Ftest\_0002fdeclarations_0002ejspdeclarations_jsp_6.java:59: Method getLoadTime() not found in class _0002fdeclarations_0002ejspdeclarations_jsp_6.
    out.print( getLoadTime() );
    ^
    C:\tomcat321\tomcat\work\localhost_8080%2Ftest\_0002fdeclarations_0002ejspdeclarations_jsp_6.java:65: Method getCurrentTime() not found in class _0002fdeclarations_0002ejspdeclarations_jsp_6.
    out.print( getCurrentTime() );
    ^
    2 errors

    Hi,
    any help on this question would be really appreciated..
    Thanx in adv,
    Ganesh

  • Char into balise jsp:scriptlet in jsp with xml syntax

    hello,
    i met a trouble with coding jsp with xml syntax,
    i use wsad to develop the jsp, and it's not allowed to put characters < or > into the balise scriptlet
    for example i cant do a loop (as i did easily with html syntax <% %> ) :
    this his the header of my jsp:
    <jsp:directive.page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
    <jsp:text>
    <![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
    </jsp:text>
    <jsp:text>
    <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> ]]>
    </jsp:text>
    and the code which dont work:
    <jsp:scriptlet>
    for (int i=0;i<10;i++){
    System.out.println(i);
    </jsp:scriptlet>
    i get a compilation error, did someone could help me to code dynamic content jsp ?
    ps: excuse me for my english.

    I don't use xml, so I may be way off the wall, but did you try using the CDATA sections again?
    <jsp:scriptlet>
    <![CDATA[
    for (int i=0;i<10;i++){
    System.out.println(i);
    ]]>
    </jsp:scriptlet>

  • IMG tag and XML syntax

    Hi,
    I want to dynamically embed image url into the IMG tag as follows:
    <jsp:useBean id="image" scope="request" class="mybeans.ImageBean" type="mybeans.ImageBean" />
    <img src='<jsp:getProperty name="image" property="imagePath"/>'    />The problem arises because of confusion with closing/opening tags getting mixed up.. How do I get this code to work if i'm using xml syntax in my jsp pages? Any solutions?
    P.

    It would be complaining about using a tag as an attribute to another tag.
    ie nesting a tag within the tag, rather than between open/close tags for it.
    Solution? Don't nest tags like this. I'm figuring you have to use an expression of some sort.
    either <img src='<%= image.getImagePath %>'/>
    or using EL in a JSP2.0 container:
    <img src='${image.imagePath}'/>
    I can't say I have done strict xml stuff, so I might be a little off, but thats the general idea.
    Hope this helps,
    evnafets

  • Standard or XML syntax?

    Which syntax is more "trendy"? And what's so special about XML syntax? All the fuss about the <jsp:text> and CDATA when writing output... And what does the jsp:text do in the first place? I read it preservs whitespace, but I didn't see the difference. And why is ${expression} said to be invalid in the J2EE tutorial? Sorry if these are funny questions but I'd really like to know it :-)

    You can find lots of example in this forum.
    Here are some of the recent ones:
    xmlp conditional region if statement inlist
    choose when syntax

  • XML syntax

    I've tried to write several simple pages using the XML syntax, but I can't solve the following problem. I have a form, where I want to prefill some values (for example the values filled in before), but I'm not able to do this using the XML syntax. Using classic JSP syntax it looks like
    <input type="text" name="firstName" value="<%=formHandler.getFirstName()%>">
    But in the XML syntax
    <input type="text" name="firstName" value="<jsp:expression>formHandler.getFirstName()</jsp:expression>">
    the compiler still complains:
    index.jsp [39:-1] Use "<" for "<" in attribute values.
    I'm sure it's pretty trivial, but I still can't solve it. I've tried several ways to escape the lt, gt signs, but that doesn't work for me.

    Hello FuzzyMac,
    In this special case, you might use EL (expression language) from JSP 2.0 (of course this might only be an option for non-production developing); in this case it might look like:
    <input type="text" name="firstName" value="${formHandler.getFirstName()}">You second example is not XML valid, because it uses also nested elements (< and > within an attribute is not allowed).
    Please have a look to an intorduction here on java.sun.com on JSP 2.0 where they explain wrinting .jspx files without EL; that might also apply to JSP 1.2 (sorry do not have the link, just search for JSP 2.0).
    Greetings, Timo

  • XML  syntax for  MULTI checkboxes

    Another XML question :
    how do I indicate multi-checkboxes?
    Meaning, instead of ticking one box, you can tick several boxes for the same field/attribute?
    Example :
    *<Field name='WhatKindOfGuy'>*
    *<Display class='???????'*
    *<Property name='Title' value='What kind of guy is Michael?'*
    Let's say I want to present a variety of options : *(a) Cheerful (b) Friendly (c) Openminded (d) Ambitious (e) Dedicated (f) Brash,* etc, etc,etc
    Obviously, Michael can be several of these things.
    So, I want to have several checkboxes.
    What's the correct XML syntax?

    In your case u have to take that many checkboxes, and finally evaluate the checkboxes selected or not on the basis of their values is true or false

  • XML syntax to revoke all the AccessControlEntry

    Hi all!!!
    I would like to know if there is an XML syntax to revoke all the AccessControlEntry of an ACL
    Thanks

    Fran wrote:
    do you know the different between PRIVATE and PUBLIC Synonym?
    Public synonyms are accessible to all users.
    Private is accessible only within its schema.
    if you don't want that this user, uses this synonym drop it and create a private synonym in the others schemas where the users need it.That doesn't fix the privilege issue though. The user can still access the table by prefixing the table with the schema name.
    You need to find out who granted the privileges on that table to the user (ie which schema) and then revoke all the privileges that were granted to that user.
    Log in as the user and execute :
    select * from user_tab_privs
    where table_name = 'YOURTABLENAME'or
    select * from dba_tab_privs
    where grantee = 'YOUR USER THAT YOU WANT TO REVOKE PRIVILEGES FROM'
    and table_name = 'TABLE_NAME that you want to revoke privileges from'Edited by: Keith Jamieson on Dec 21, 2012 2:16 PM

  • XML Syntax Highlighting

    Hi, I need help with XML Syntax Highlighting. I try to create simple XML editor, but I have probleblems with Syntax Highlighting.
    Is there anyone who can help me?

    Here is personal recommendation, this 3rd party syntax highlight component works quite well for many JTextComponents
    Check out: http://ostermiller.org/syntax/
    ICE

  • XML Syntax highlighting (again :)

    Hi there,
    I know, that there have been quite a view posts about this topics, but as far as I see, there has been no solution to this.
    So I wanted to ask if someone has implemented a XML Syntax highlighting or knows where to get a tutorial from to accomplish so (inheriting from DefaultStyledDocument...?)
    Sincerely
    Charly

    Hi!
    I have the same need: an XML Syntax Highlighting (coloring).
    I don't need an XML editor, I have a JTextPane that shows XML code and I would like it to be done with a syntax coloring.
    If you have a solution I will really appreciate!
    Thanks
    Gio :-)

  • XML syntax for tags

    It has always been a habit of mine to use XML syntax for CF tags since I've been working with XHTML. For instance, I will do <cfset var myVar = "" /> However, I noticed when doing <cfdump var"#myvar#" />, the output is displayed twice. So now I am wondering if whenever I use a /> on something such as cfset, is the tag actually executing twice? How does this affect performance?
    I just happened to notice that in CFBuilder, when I do <cfargment name="myVar" required="true" type="string" default="" />, when I go to the next line and start typing <cfarg auto-suggest will select the cfargument tag, but this is only if I use a />. If I omit the ending forward-slash, auto-suggest does not work. That may be a setting specific to CFBuilder, but that wasn't the scope of this question.
    What syntax is correct and how does it affect performance?

    According to the document I've linked to below; using self-closing CF tags, such as <cfset myname="Bob" /> is permissible.  The document also notes exceptions to this such as CFIF and custom tags as examples where a self-closing tag shouldn't be used.
    http://livedocs.adobe.com/wtg/public/coding_standards/style.html
    Althoguh it doesn't look like it, that's an internal coding standard for one of Adobe's (well: it was Macromedia at the time) internal teams, and is not supposed to be a suggested standard for everyone.  I've had this same discussion with them, too.
    As Owainnorth (and many others) observe, it's completely doable.  My only challenge to it (and it's a challenge I state in an unduly heavy-handed fashion sometimes!) is the nonsensical rationales people use for doing it: making it more like XML, it's good if the CFML blends in better with the XHTML mark-up it's generating, it's tidier, etc.
    I hasten to add that Owainnorth's position that he finds it easier to read and assists with code navigation, whilst leaving me with a blank look on my face, is a completely reasonable basis for doing it.  I personally don't believe it, but there's no reason why that should bother him (and I'm sure it doesn't).
    I think it was reasonable of me to challenge his wording that it's easier to identify where CF code blocks are by looking at the closing slash rather than the tag name; but having explained himself better, I reckon it's not quite so much tosh as it originally sounded.  I mean: I still can't see it, but obviously he can, so fair enough.
    Adam

  • How to read an attribute of an xml tag in jsp.

    hi guys,
    This is murali krishna. i have a small problem,
    i have one xml file (books.xml)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <library>
    <book id="1">
    <name>Head First Java, 2nd Edition</name>
    <author>Kathy Sierra and Bert Bates</author>
    <publication-date>09-Feb-2005</publication-date>
    </book>
    <book id="2">
    <name>Effective Java</name>
    <author>Joshua Bloch</author>
    <publication-date>28-May-2008</publication-date>
    </book>
    <book id="3">
    <name>Java How to Program, 7th Edition</name>
    <author>Harvey M. Deitel and Paul J. Deitel</author>
    <publication-date>6-Jan-2007</publication-date>
    </book>
    </library>
    I tried to read this xml file in jsp as shown below
    <%@ page language="java" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="javax.xml.parsers.DocumentBuilder" %>
    <%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
    <%
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db =dbf.newDocumentBuilder();
    Document doc=db.parse("c:\\books.xml");
    NodeList nl = doc.getElementsByTagName("book");
    %>
    <html>
    <head>
    <title>How to read XML file in JAVA</title>
    </head>
    <body>
    <%
    for(int i=0;i<nl.getLength();i++)
    NodeList nameNlc= doc.getElementsByTagName("name");
    Element nameElements=(Element)nameNlc.item(i);
    String nameTagValue=nameElements.getChildNodes().item(0).getNodeValue();
    NodeList authorNlc= doc.getElementsByTagName("author");
    Element authorElements=(Element)authorNlc.item(i);
    String authorTagValue=authorElements.getChildNodes().item(0).getNodeValue();
    NodeList dateNlc= doc.getElementsByTagName("publication-date");
    Element dateElements=(Element)dateNlc.item(i);
    String dateTagValue=dateElements.getChildNodes().item(0).getNodeValue();
    out.println("name :"+nameTagValue+"<br>");
    out.println("author :"+authorTagValue+"<br>");
    out.println("publication-date :"+dateTagValue+"<br><br>");
    %>
    </body>
    </html>
    so, my problem is I was unable to read the attribute of the tag book , that is "id".
    can any one tell me how to read this "id" attribute.
    Murali Krishna
    [email protected]

    hi,
    U r retriving the elements by tag name.So it just chks the tag name ie.<book> & gives u array of elements.But u need retrive d attribute of <book> tag itself.
    =Solution =====
    Add one more statement ----> var[]= doc.getElementsByName("book");
    Now u hav book elements as an array & can retrive id in for loop
    for(var; var.length;var++)
    doc.element[var].id.value

  • Use of xml files in JSP ??

    I wud like to know the wy we use XML files in JSP's or in any web development applications.

    Transferring information in own markup language.
    http://www.google.com/search?q=xml+tutorial+site:w3schools.com

  • Please help; how to write XML document with JSP?

    I try to write XML document with JSP...
    But I got wrong results everytime.
    The result is not XML file displayed in the browser,
    but HTML file.
    I even tried to use HTML special code for <, >, "
    but still display as HTML file not XML file.
    How to do this?
    Thanks in advance. I put my codes below.
    Sincerely,
    Ted.
    ================
    Here is code for the JSP (called stk.jsp):
    <%@ page contentType="text/xml" %>
    <%@ page import="bean.Stock" %>
    <jsp:useBean id="portfolio" class="bean.Portfolio" />
    <% java.util.Iterator pfolio = portfolio.getPortfolio();
    Stock stock = null; %>
    <?xml version="1.0" encoding="UTF-8"?>
    <portfolio>
    <% while (pfolio.hasNext())
    stock = (Stock) pfolio.next(); %>
    <stock>
    <symbol>
    <%=stock.getSymbol() %>
    </symbol>
    <name><%=stock.getName() %> </name>
    <price><%=stock.getPrice() %> </price>
    </stock>
    <% } %>
    </portfolio>
    =================
    Here is the code for bean.Stock:
    package bean;
    public class Stock implements java.io.Serializable
    String symbol, name;
    float price;
    public Stock(String symbol, String name, float price)
    this.symbol = symbol;
    this.name = name;
    this.price = price;
    public String getSymbol()
    return symbol;
    public String getName()
    return name;
    public float getPrice()
    return price;
    ===============
    And here is bean.Portfolio:
    package bean;
    import java.util.Iterator;
    import java.util.Vector;
    public class Portfolio implements java.io.Serializable
    private Vector portfolio = new Vector();
    public Portfolio()
    portfolio.addElement(new Stock("SUNW", "Sun Microsystem", 34.5f));
    portfolio.addElement(new Stock("HWP", "Hewlett Packard", 15.15f));
    portfolio.addElement(new Stock("AMCC", "Applied Micro Circuit Corp.", 101.35f));
    public Iterator getPortfolio()
    return portfolio.iterator();
    }

    Hi
    I'm not sure whta your query is but I tested your code as it is has been pasted and it seems to work fine. There is an XML output that I'm getting.
    Keep me posted.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems
    http://www.sun.com/developers/support

  • XML Messaging and JSP.  Is it possible?

    Here is my situation.
    We are developing JSP with a backend interface to external/remote Java/C++ applications. We like to implment, if possible, XML messaging between JSP and remote programs.
    First of all, is this possible? Can JAXM be used in JSP?
    Thanks in advance.

    Sure, but you might need to use polling for the JSP to get the response to show the user.

Maybe you are looking for