• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Expression Language

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jun Liu,

I didn't noticed it. Thank you very much. The code is working fine now.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic