aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request-Time Attribute Expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request-Time Attribute Expressions" Watch "Request-Time Attribute Expressions" New topic
Author

Request-Time Attribute Expressions

luis meira
Ranch Hand

Joined: Apr 18, 2002
Posts: 55
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
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
<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 <%=***%>.


Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
If you want to use XML style you need
<jsp:root ...> tag and you can not mix XML style with the standard style.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
luis meira
Ranch Hand

Joined: Apr 18, 2002
Posts: 55
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

Joined: Aug 22, 2002
Posts: 78
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

Joined: Apr 18, 2002
Posts: 55
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

Joined: Apr 18, 2002
Posts: 55
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

Joined: Aug 22, 2002
Posts: 78
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

Joined: Apr 18, 2002
Posts: 55
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

Joined: Aug 22, 2002
Posts: 78
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.
Maha Annadurai
Ranch Hand

Joined: Oct 27, 2002
Posts: 87
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request-Time Attribute Expressions