You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Stefan <ni...@studioweb.com> on 2002/10/11 01:28:44 UTC

Is there a way to call java.lang.String.substring on a
Hi,

I would like to use substring on a c: out like so:

<c:out value="${value.activity.substring(0,4)}"/>

It works but at the same time I get this error:

500 Servlet Exception 
java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at com.caucho.el.MethodExpr.evalObject(MethodExpr.java:105)
	at com.caucho.el.Expr.print(Expr.java:207)
	at _testcode._jstl__jsp._jspService(/TESTCODE/jstl.jsp:103)
	at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
	at com.caucho.jsp.Page.subservice(Page.java:485)
	at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
	at com.caucho.server.http.Invocation.service(Invocation.java:312)
	at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
	at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
	at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
	at java.lang.Thread.run(Thread.java:536)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out
of range: 4
	at java.lang.String.substring(String.java:1477)
	... 15 more

Any tips would be appreciated,
Stef


Re: Is there a way to call java.lang.String.substring on a Posted by Jungho Kim <ju...@sympatico.ca>.
The value of c:out is output to the JspWriter instance for the page at
runtime and as such it would not be possible to do what you are suggesting
from within a jsp page.  As Shawn suggested take a look at the String
taglib.  It actually has a tag called "substring".

regards,

Jungho
----- Original Message -----
From: "Stefan" <ni...@studioweb.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Thursday, October 10, 2002 10:15 PM
Subject: Re: Is there a way to call java.lang.String.substring on a <c: out
?


> Shawn,
>
> So is there a way to extract a sub string from the result of a <c:out
> value="${}}"/> tag?
>
> Thanks,
>
> Stef
>
>
>
>
> ----- Original Message -----
> From: "Shawn Bayern" <ba...@essentially.net>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> Sent: Thursday, October 10, 2002 9:01 PM
> Subject: Re: Is there a way to call java.lang.String.substring on a <c:
out
> ?
>
>
> > On Thu, 10 Oct 2002, Stefan wrote:
> >
> > > Hi,
> > >
> > > I would like to use substring on a c: out like so:
> > >
> > >
> >
> > No, this can't be done in JSTL 1.0.  You'll be able to define functions
in
> > the EL in JSP 2.0, but for now, any attempt to do so should yield a
> > translation-time error, as the syntax isn't supported.
> >
> > > It works but at the same time I get this error:
> > >
> > > 500 Servlet Exception
> > > java.lang.reflect.InvocationTargetException
> > > at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
> > > at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
> > > at java.lang.reflect.Method.invoke(Method.java:324)
> > > at com.caucho.el.MethodExpr.evalObject(MethodExpr.java:105)
> >
> > You might want to mail the Caucho folks and ask them about this; their
> > implementation is different from Jakarta Taglibs's.  Note again that it
> > *shouldn't* work; if it does, then an implementation isn't
JSTL-compliant.
> >
> > You can use other tag libraries like the String Taglib to perform string
> > manipulation in your JSP pages.
> >
> > --
> > Shawn Bayern
> > "JSTL in Action"   http://www.jstlbook.com
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Stefan <ni...@studioweb.com>.
Forget it - I needid to add the commons jar.

Thanks.
----- Original Message -----
From: "Stefan" <ni...@studioweb.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Friday, October 11, 2002 12:45 AM
Subject: Re: Is there a way to call java.lang.String.substring on a <c:out ?


> Hi,
>
> I just installed the string  taglib and tried the simple example as found
in
> the docs:
>
> <str:substring start="4" end="8">The tree is green.</str:substring>
>
> And I get this error:
>
> org/apache/commons/lang/NumberUtils
>
> I am using Resin 2.1.4 and placed the string.jar file into the web
> applications WEB-INF\lib folder and added the discriptor file to:
>
> WEB-INF\classes\tlds
>
> And finally I added this to the web.xml file:
>
> <taglib>
>   <taglib-uri>http://jakarta.apache.org/taglibs/string-1.0</taglib-uri>
>   <taglib-location>/WEB-INF/string.tld</taglib-location>
> </taglib>
>
>
> Any ideas what I am doing wrong?
>
> Thanks
>
> ----- Original Message -----
> From: "Tim Kettering" <ti...@mac.com>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> Sent: Friday, October 11, 2002 12:17 AM
> Subject: Re: Is there a way to call java.lang.String.substring on a <c:out
?
>
>
> >
> > http://jakarta.apache.org/taglibs/doc/string-doc/intro.html
> >
> > I'd suggest using the Strings taglib.  Its really very nice, and comes
> with
> > a whole lot of other goodies you can use as well, rather than making a
> > one-off bean method that does the same thing.
> >
> > <str:substring start="4" end="8">
> > <c:out value="${param.name}"/></str:substring>
> >
> > Or something like that.
> >
> >
> > > So I would wrap the <c:out  value="${}}"/> tag with a JSTL string
taglib
> or
> > > perhaps a bean method that returns a string like so:
> > >
> > > <%=  myBean.myStringMethod(<c:out  value="${param.name}}"/>) %>
> > >
> > >
> > > Thanks
> > >
> > >
> > > ----- Original Message -----
> > > From: "Shawn Bayern" <ba...@essentially.net>
> > > To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> > > Sent: Thursday, October 10, 2002 11:36 PM
> > > Subject: Re: Is there a way to call java.lang.String.substring on a
<c:
> out
> > > ?
> > >
> > >
> > >> On Thu, 10 Oct 2002, Stefan wrote:
> > >>
> > >>> So is there a way to extract a sub string from the result of a
<c:out
> > >>> value="${}}"/> tag?
> > >>
> > >> No, not alone; you'd need to use the String Taglib or handle it with
a
> > >> servlet or other custom Java logic (e.g., a bean or servlet).
> > >>
> > >> --
> > >> Shawn Bayern
> > >> "JSTL in Action"   http://www.jstlbook.com
> > >>
> > >>
> > >> --
> > >> To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > >> For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >>
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> > >
> >
> > --
> > Tim Kettering
> > timster@mac.com
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Stefan <ni...@studioweb.com>.
Hi,

I just installed the string  taglib and tried the simple example as found in
the docs:

<str:substring start="4" end="8">The tree is green.</str:substring>

And I get this error:

org/apache/commons/lang/NumberUtils

I am using Resin 2.1.4 and placed the string.jar file into the web
applications WEB-INF\lib folder and added the discriptor file to:

WEB-INF\classes\tlds

And finally I added this to the web.xml file:

<taglib>
  <taglib-uri>http://jakarta.apache.org/taglibs/string-1.0</taglib-uri>
  <taglib-location>/WEB-INF/string.tld</taglib-location>
</taglib>


Any ideas what I am doing wrong?

Thanks

----- Original Message -----
From: "Tim Kettering" <ti...@mac.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Friday, October 11, 2002 12:17 AM
Subject: Re: Is there a way to call java.lang.String.substring on a <c:out ?


>
> http://jakarta.apache.org/taglibs/doc/string-doc/intro.html
>
> I'd suggest using the Strings taglib.  Its really very nice, and comes
with
> a whole lot of other goodies you can use as well, rather than making a
> one-off bean method that does the same thing.
>
> <str:substring start="4" end="8">
> <c:out value="${param.name}"/></str:substring>
>
> Or something like that.
>
>
> > So I would wrap the <c:out  value="${}}"/> tag with a JSTL string taglib
or
> > perhaps a bean method that returns a string like so:
> >
> > <%=  myBean.myStringMethod(<c:out  value="${param.name}}"/>) %>
> >
> >
> > Thanks
> >
> >
> > ----- Original Message -----
> > From: "Shawn Bayern" <ba...@essentially.net>
> > To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> > Sent: Thursday, October 10, 2002 11:36 PM
> > Subject: Re: Is there a way to call java.lang.String.substring on a <c:
out
> > ?
> >
> >
> >> On Thu, 10 Oct 2002, Stefan wrote:
> >>
> >>> So is there a way to extract a sub string from the result of a <c:out
> >>> value="${}}"/> tag?
> >>
> >> No, not alone; you'd need to use the String Taglib or handle it with a
> >> servlet or other custom Java logic (e.g., a bean or servlet).
> >>
> >> --
> >> Shawn Bayern
> >> "JSTL in Action"   http://www.jstlbook.com
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
> --
> Tim Kettering
> timster@mac.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Stefan <ni...@studioweb.com>.
Hi,

This Strings taglib is not part of JSTL right? And if this is so I guess
JSTL does not include this sort of string manipulation capability?


Thanks
----- Original Message -----
From: "Tim Kettering" <ti...@mac.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Friday, October 11, 2002 12:17 AM
Subject: Re: Is there a way to call java.lang.String.substring on a <c:out ?


>
> http://jakarta.apache.org/taglibs/doc/string-doc/intro.html
>
> I'd suggest using the Strings taglib.  Its really very nice, and comes
with
> a whole lot of other goodies you can use as well, rather than making a
> one-off bean method that does the same thing.
>
> <str:substring start="4" end="8">
> <c:out value="${param.name}"/></str:substring>
>
> Or something like that.
>
>
> > So I would wrap the <c:out  value="${}}"/> tag with a JSTL string taglib
or
> > perhaps a bean method that returns a string like so:
> >
> > <%=  myBean.myStringMethod(<c:out  value="${param.name}}"/>) %>
> >
> >
> > Thanks
> >
> >
> > ----- Original Message -----
> > From: "Shawn Bayern" <ba...@essentially.net>
> > To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> > Sent: Thursday, October 10, 2002 11:36 PM
> > Subject: Re: Is there a way to call java.lang.String.substring on a <c:
out
> > ?
> >
> >
> >> On Thu, 10 Oct 2002, Stefan wrote:
> >>
> >>> So is there a way to extract a sub string from the result of a <c:out
> >>> value="${}}"/> tag?
> >>
> >> No, not alone; you'd need to use the String Taglib or handle it with a
> >> servlet or other custom Java logic (e.g., a bean or servlet).
> >>
> >> --
> >> Shawn Bayern
> >> "JSTL in Action"   http://www.jstlbook.com
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
> --
> Tim Kettering
> timster@mac.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Tim Kettering <ti...@mac.com>.
http://jakarta.apache.org/taglibs/doc/string-doc/intro.html

I'd suggest using the Strings taglib.  Its really very nice, and comes with
a whole lot of other goodies you can use as well, rather than making a
one-off bean method that does the same thing.

<str:substring start="4" end="8">
<c:out value="${param.name}"/></str:substring>
       
Or something like that.


> So I would wrap the <c:out  value="${}}"/> tag with a JSTL string taglib or
> perhaps a bean method that returns a string like so:
> 
> <%=  myBean.myStringMethod(<c:out  value="${param.name}}"/>) %>
> 
> 
> Thanks
> 
> 
> ----- Original Message -----
> From: "Shawn Bayern" <ba...@essentially.net>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> Sent: Thursday, October 10, 2002 11:36 PM
> Subject: Re: Is there a way to call java.lang.String.substring on a <c: out
> ?
> 
> 
>> On Thu, 10 Oct 2002, Stefan wrote:
>> 
>>> So is there a way to extract a sub string from the result of a <c:out
>>> value="${}}"/> tag?
>> 
>> No, not alone; you'd need to use the String Taglib or handle it with a
>> servlet or other custom Java logic (e.g., a bean or servlet).
>> 
>> --
>> Shawn Bayern
>> "JSTL in Action"   http://www.jstlbook.com
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Tim Kettering
timster@mac.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Stefan <ni...@studioweb.com>.
So I would wrap the <c:out  value="${}}"/> tag with a JSTL string taglib or
perhaps a bean method that returns a string like so:

<%=  myBean.myStringMethod(<c:out  value="${param.name}}"/>) %>


Thanks


----- Original Message -----
From: "Shawn Bayern" <ba...@essentially.net>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Thursday, October 10, 2002 11:36 PM
Subject: Re: Is there a way to call java.lang.String.substring on a <c: out
?


> On Thu, 10 Oct 2002, Stefan wrote:
>
> > So is there a way to extract a sub string from the result of a <c:out
> > value="${}}"/> tag?
>
> No, not alone; you'd need to use the String Taglib or handle it with a
> servlet or other custom Java logic (e.g., a bean or servlet).
>
> --
> Shawn Bayern
> "JSTL in Action"   http://www.jstlbook.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Shawn Bayern <ba...@essentially.net>.
On Thu, 10 Oct 2002, Stefan wrote:

> So is there a way to extract a sub string from the result of a <c:out
> value="${}}"/> tag?

No, not alone; you'd need to use the String Taglib or handle it with a
servlet or other custom Java logic (e.g., a bean or servlet).

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Stefan <ni...@studioweb.com>.
Shawn,

So is there a way to extract a sub string from the result of a <c:out
value="${}}"/> tag?

Thanks,

Stef




----- Original Message -----
From: "Shawn Bayern" <ba...@essentially.net>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Thursday, October 10, 2002 9:01 PM
Subject: Re: Is there a way to call java.lang.String.substring on a <c: out
?


> On Thu, 10 Oct 2002, Stefan wrote:
>
> > Hi,
> >
> > I would like to use substring on a c: out like so:
> >
> >
>
> No, this can't be done in JSTL 1.0.  You'll be able to define functions in
> the EL in JSP 2.0, but for now, any attempt to do so should yield a
> translation-time error, as the syntax isn't supported.
>
> > It works but at the same time I get this error:
> >
> > 500 Servlet Exception
> > java.lang.reflect.InvocationTargetException
> > at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
> > at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:324)
> > at com.caucho.el.MethodExpr.evalObject(MethodExpr.java:105)
>
> You might want to mail the Caucho folks and ask them about this; their
> implementation is different from Jakarta Taglibs's.  Note again that it
> *shouldn't* work; if it does, then an implementation isn't JSTL-compliant.
>
> You can use other tag libraries like the String Taglib to perform string
> manipulation in your JSP pages.
>
> --
> Shawn Bayern
> "JSTL in Action"   http://www.jstlbook.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is there a way to call java.lang.String.substring on a Posted by Shawn Bayern <ba...@essentially.net>.
On Thu, 10 Oct 2002, Stefan wrote:

> Hi,
> 
> I would like to use substring on a c: out like so:
> 
> <c:out value="${value.activity.substring(0,4)}"/>

No, this can't be done in JSTL 1.0.  You'll be able to define functions in
the EL in JSP 2.0, but for now, any attempt to do so should yield a
translation-time error, as the syntax isn't supported.

> It works but at the same time I get this error:
> 
> 500 Servlet Exception 
> java.lang.reflect.InvocationTargetException
> 	at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at com.caucho.el.MethodExpr.evalObject(MethodExpr.java:105)

You might want to mail the Caucho folks and ask them about this; their
implementation is different from Jakarta Taglibs's.  Note again that it
*shouldn't* work; if it does, then an implementation isn't JSTL-compliant.

You can use other tag libraries like the String Taglib to perform string
manipulation in your JSP pages.

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>