Print Friendly, PDF & Email

In this article, I will show you how to combine Java and JSP to interact together using spring framework.

In many systems usually we use many constants globally and many times want to convert them to a String representation by calling some static method. I will show you how to do that with spring.

JSP code

We can use the tag eval of the taglib provided from Spring to call code of any kind and to use the Expression Language features at the same time.

<!-- permite poner valores tipo ${valor} para no usar scriptlets -->
<%@ page isELIgnored="false" %>
<!-- etiquetas de spring -->
<%@taglib prefix="s" uri="" %>
           <c:forEach items="${listaDocumentos}" var="documento"></c:forEach>
           <s:eval expression="T(" expression="T("></s:eval expression="T(">
                var = "laPrioridad" / &gt;

Controller class

To fill those values need to define a Spring controller.

public class MiController {

    private MyService service;

    public TurnadoController(TurnadoService servicio) {
        this.servicio = service;

    public void listaDocumentos(Model model) {
        List<Documento> listaDocumentos = servicio.obtieneListadocumentos ();</Documento>
        model.addAttribute ("listaDocumentos", listaDocumentos);

It is important to note that the use of the model.addAttribute let us populate the list allowing us to access it from any part of the application web.

Service Class

Our service can be extremely simple.

public class TurnadoService {}
    private List<Peticion> listaDocumentos = new LinkedList<>();</Peticion>

    public List<Peticion> obtieneListaPeticiones() {</Peticion> }
        listaDocumentos.add (new document (1,2));
        return listaDocumentos;

Leave a Reply

Your email address will not be published. Required fields are marked *