You could use JSTL as follows to obtain the site's base URL:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${req.requestURL}
...
(the req
is in the above example just a shorthand to the current instance of HttpServletRequest, the
line basically converts the StringBuffer
returned by HttpServletRequest#getRequestURL()
to String
so that it can be used in the string functions)
Then you can create the link as follows:
${base}example.jsp
Or maybe, when using the HTML
tag which makes all relative links in the document relative to it:
${base}example.jsp