Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Expression Language

 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was trying the sample program of SCWCD Exam Study Kit 2nd Edition shown chapter 13. Below are the details:

1) StrMethods.java

package myFunc;

public class StrMethods{
public static String upper(String x){
return x.toUpperCase();
}

public static int length(String x){
return x.length();
}
}

2) Functions.tld

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">

<tlib-version>1.0</tlib-version>
<function>
<name>upper</name>
<function-class>myFunc.StrMethods</function-class>
<function-signature>
java.lang.String upper(java.lang.String)
</function-signature>
</function>
<function>
<name>length</name>
<function-class>myFunc.StrMethods</function-class>
<function-signature>
java.lang.int length(java.lang.String)
</function-signature>
</function>
</taglib>

3) deployment descriptor

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<taglib>
<taglib-uri>
http://myFunc/Functions
</taglib-uri>
<taglib-location>
/WEB-INF/myFunc/Functions.tld
</taglib-location>
</taglib>

</web-app>

4) Stringfun.jsp

<%@ taglib prefix="myString" uri="http://myFunc/Functions" %>
<html>
<body>
<b>Enter Text : </b>
<form action="Stringfun.jsp" method="GET">
<input type="text" name="str">
<p><input type="submit">
</form>
<% String x = request.getParameter("str"); %>

<table border="1">
<tr>
<td>Uppercase:</td>
<td>${myString:upper('str')}</td>
</tr>
<tr>
<td>Length:</td>
<td>${myString:length("str")}</td>
</tr>
</table>
</body>
</html>

Location of the files: (I'm using Tomcat 5)
1. StrMethods.class --> inside webapps/chapter13/WEB-INF/classes/myFunc
2. Functions.tld --> inside webapps/chapter13/WEB-INF/myFunc
3. web.xml --> inside webapps/chapter13/WEB-INF
4. Stringfun.jsp --> inside webapps/chapter13

The output should display to uppercase the string that the user entered in the text field and also display the length of the string.
However when I run this: http://localhost/chapter13/Stringfun.jsp. I'm not getting what I expected.
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Related with the above post..

In Stringfun.jsp, I forgot to remove the single/double quotes in the EL.

It should be,

${myString:upper(str)} and
${myString:length(str)}

Sorry for that.. But I still get the same problem.
 
Jun Liu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Rex:
Hi,

Related with the above post..

In Stringfun.jsp, I forgot to remove the single/double quotes in the EL.

It should be,

${myString:upper(str)} and
${myString:length(str)}

Sorry for that.. But I still get the same problem.



It should be ${myString:upper(param.str)} and ${myString:length(param.str).
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jun Liu,

I didn't noticed it. Thank you very much. The code is working fine now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic