J
J
justboris2012-03-28 11:38:00
Java
justboris, 2012-03-28 11:38:00

How to get hostName in Freemarker?

There is a project on SpringMVC. Freemarker is the templating engine. On one of the pages you need to insert a full link, that is, with an indication of the domain.
In jsp this is solved by inserting ${request.getServerName()}. In freemarker the same code doesn't work.
You can also calculate the hostname in the controller and pass it to the view, but this violates the MVC principle.
How can you find out the hostname in the freemarker template anyway?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akkuch, 2012-03-28
@akkuch

It says here that if the template engine is launched using freemarker.ext.servlet.FreemarkerServlet, then three objects pass through the entire request in the template engine - Request, Session, Application. In addition, there is also a hash RequestParametersthat contains all the request parameters.
As far as I know, I may be wrong, but in the context of Spring, Freemarker templates have a url object . Then the server name can be obtained like this:
${url.server}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question