• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Request-Time Attribute Expressions

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,

i'm currently playing with xml jsp syntax and i'm looking at the diferences between the normal JSP systax and xml one.
i would like to know the equivalent to this code example in the xml syntax :
<html>
<body>
<form>
<input type="button" value='<%="Teste"%>' />
</form>
</body>
</html>
i know that this doesn't compile :
<input type="button" value='<jsp:expression>Teste</jsp:expression>' />

any ideas
best regards
Lu�s Filipe Meira
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<input type="button" value='<%="Teste"%>' />
would be:
<input type="button" value='%="Teste"%' />

For request-time attribute values, the only difference for XML syntax is to remove the <> from <%=***%>.
 
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to use XML style you need
<jsp:root ...> tag and you can not mix XML style with the standard style.
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kyle Tang:
<input type="button" value='<%="Teste"%>' />
would be:
<input type="button" value='%="Teste"%' />

For request-time attribute values, the only difference for XML syntax is to remove the <> from <%=***%>.


thanks but it doesn't work.
i get this exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 16 in the jsp file: /teste.jsp
Generated servlet error:
C:\Java\tomcat\work\localhost\eshop\teste$jsp.java:82: ')' expected.
out.write("<input type=\"button\" value='%="Teste"%'>");
do u you have any more ideas ?
best regards
Lu�s Meira
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait a minute, <input ....>, is that a html element? you can only use request-time attr-value for certain JSP actions, ie:
<jsp:useBean> with beanName
<jsp:setProperty> with value
<jsp aram> with value
<jsp:include> with page
<jsp:forward> with page
(I am probably missing something here)
and your custom tag may have request-time attr-value if you define that in your tld file.
Nothing else could have request-time attr-value.
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kyle Tang:
wait a minute, <input ....>, is that a html element? you can only use request-time attr-value for certain JSP actions, ie:
<jsp:useBean> with beanName
<jsp:setProperty> with value
<jsp aram> with value
<jsp:include> with page
<jsp:forward> with page
(I am probably missing something here)
and your custom tag may have request-time attr-value if you define that in your tld file.
Nothing else could have request-time attr-value.


Kyle,
i can do this with Jsp syntax, i only have a problem when i use the xml syntax.
for short :
Jsp Syntax
<input type="button" value='<%="Teste"%>' />
this works, without problems
Xml Syntax
<input type="button" value='%="Teste"%' />
this dosen't.
any ideas ?
best regards
LFM
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by :
[QB][/QB]



here you have.
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/teste.jsp";from=(0,0);to=(4,28)]
out.write("\r\n<html>\r\n<body>\r\n<form>\r\n<input type=\"button\" value='");
// end
// begin [file="/teste.jsp";from=(4,31);to=(4,38)]
out.print("Teste");
// end
// HTML // begin [file="/teste.jsp";from=(4,40);to=(12,0)]
out.write("' />\r\n</form>\r\n</body>\r\n</html>\r\n\r\n\r\n\r\n\r\n");
// end
} catch (Throwable t) {
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry I already deleted my last post. but thanks for the post.
the point is it is NOT a "request-time attribute", it is a JSP expression. so what you need is <jsp:expression>.
so you may try this:
<jsp:text>
<html>
...
<input ... value=</jsp:text>
<jsp:expression>"Teste"</jsp:expression>
<jsp:text> ...</jsp:text>
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello again,
i've tried this but also no go.
<jsp:root version="1.2" >
<jsp:test>
<html>
<body>
<form>
<input type="button" value= '</jsp:text><jsp:expression>"Teste"</jsp:expression>
<jsp:text> ' />
</form>
</body>
</html>
</jsp:text>
</jsp:root>
i got this exception :
org.apache.jasper.compiler.ParseException: /teste.jsp(6,31) The value of attribute "value" must not contain the '<' character.
i'm runing out of ideas.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the one that will finally work:
<jsp:root version="1.2" >
<jsp:text>
<![CDATA[
<html>
<body>
<form>
<input type="button" value= ']]>
</jsp:text><jsp:expression>"Teste"</jsp:expression>
<jsp:text><![CDATA[' />
</form>
</body>
</html>]]>
</jsp:text>
</jsp:root>

please note, in XML, your "<html>" becomes an XML element! So we can't just use <html> or <body> in plain, in a XML file. You need to either use < to replace '<', or use CDATA.
CDATA has syntax:
<!CDATA[
.... (your text here)
]]>
Everything in CDATA becomes pure characters. They won't be taken as XML tags.
You may want to know more about XML and CDATA from some XML books.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a working example, I tried with Tomcat 4.0
<jsp:root
xmlns:jsp="http://java.sun/com/JSP/Page"
version = "1.2"
>
<jsp:scriptlet>
String name ="Maha Annadurai";
</jsp:scriptlet>
<jsp:text>
<html>
<body>
Hello, How are you?
<jsp:expression> name </jsp:expression>
</body>
</html>
</jsp:text>
</jsp:root>
[ November 30, 2002: Message edited by: Maha Annadurai ]
reply
    Bookmark Topic Watch Topic
  • New Topic