Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jstl

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 am getting the error

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

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

like image 410
P Hemans Avatar asked Jun 16 '11 04:06

P Hemans


1 Answers

StringBuffer#toString() is definitely the right method to call. The problem is calling it using EL. You can convert it to 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, '')}" />

That said, I think there's a better way to get the output string you want that doesn't use fn:replace.

like image 79
Matt Ball Avatar answered Oct 12 '22 22:10

Matt Ball