Hy guys, I apologize if this is a stupid question, but I couldn't find any examples on how to do this.
My expression is currently ${fn:substringBefore(var1, \"@\")}@domain.com
.
I've been trying multiple ways of adding the '@domain' string at the end, but none of them seem to work.
Could you let me know if this is at least possible?
Disclaimer: I've never used JSTL, but I've learned a lot of technologies, most of them alone, by just reading the materials available online. So this answer is more about the thought process involved in solving these when I'm stuck.
When learning new technologies it's usually best to start at the documentation and examples. In this case just by searching for jstl fn:substringBefore
I've found this page where fn-substringbefore section has the following example:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>Using JSTL Function </title>
</head>
<body>
<c:set var="string" value="Hi, This is JAVATPOINT.COM developed by SONOO JAISWAL."/>
${fn:substringBefore(string, "developed")}
</body>
</html>
So it seems like this function should be used by referencing a string (found in the previous line of the example) that will be split at the second argument, returning the first part of the split.
Also the "
-s are not escaped in the example, so I would try something like.
${fn:substringBefore(referenceToFullEmailAddress, "@")}
All this is assuming that what you were trying to achieve was to retrieve the first part of the email address, before the @domain.com
part.
This is also a reason why it's always a good practice to include more context in your questions.