The replace (String, String, String) method in the Function type is not applicable for arguments (StringBuffer, String, String)

Here is my jsp file:

<%@ page contentType="text/plain" %> <%@ page pageEncoding="UTF-8"%><%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <c:out value="${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, '')}" /><c:out value="${model.uri}" /> 

I get an error

 The method replace(String, String, String) in the type Functions is not applicable for the arguments (StringBuffer, String, String) 

I tried pageContext.request.requestURL.toString (), but toString () is apparently not a method. Any suggestions?

+4
source share
3 answers

StringBuffer#toString() is definitely the right method to call. The problem is causing it using EL. You can convert it to a string using <c:set> as described in this answer .

 <c:set var="url">${pageContext.request.requestURL}</c:set> <c:out value="${fn:replace(url, pageContext.request.requestURI, '')}" /> 

However, I think there is a better way to get the right output string that doesn't use fn:replace .

+7
source
 pageContext.request.requestURL.toString() 

Must work.

0
source

try "" + pageContext.request.requestURL instead of pageContext.request.requestURL.toString()

-1
source

All Articles