1

I'm using Maven and Spring and my EL doesn't seem to be working on my JSP. I end up seeing this as a result.

this

The JSPs work and the GET and POST methods seem to be functioning fine. It just doesn't seem to recognize the EL. I have have tried using JSTL too but both the EL and JSTL expressions are read as static text. I've been trying every combination of dependencies I could find but to no avail. If anyone has had issues with this before please help.

POM.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test-springboot-mvc</groupId>
<artifactId>test-springboot-mvc</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
    <relativePath />
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springboot.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Application.java:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Configuration file

package mvc.configuration;

import {...}

@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
    @Bean
    public ViewResolver getViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setViewClass(JstlView.class);
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");

        return resolver;
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}

Controller

@Controller
public class FormController {

    @RequestMapping(value = "/form", method = RequestMethod.GET)
    public String formGet(Model model) {
        model.addAttribute("id2", "ID:");
        model.addAttribute("unBoundTextBox", "Initial Value");
        return "form";
    }

    @RequestMapping(value = "/form", method = RequestMethod.POST)
    public String formPost(@RequestParam("unBoundTextBox") String unBoundTextValue) {
        System.out.println("POSTBACK SUBMIT textbox value = " + unBoundTextValue);

        return "form";
    }
}

JSP:

<h2>new form</h2>
{id2}
<form action="/form" method="post">
    <input type="text" name="unBoundTextBox" value="${unBoundTextBox}" />
    <button>Submit</button>
</form>
3
  • Jstl is a tag library, but the form is not use jstl.
    – Roman C
    Feb 12, 2018 at 2:42
  • Alex, the ${xxx} things is called EL, not JSTL. JSTL are those <c:xxx> tags.
    – BalusC
    Feb 12, 2018 at 7:25
  • @BalusC Thank you, you're right. However I saw the similar questions/answers and it didn't solve why the EL didn't work. Nor did any actual JSTL that I tried. But as it turns out, I had to add the javax.servlet-api dependency to make it work. I was using Maven 3.5.2 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> Feb 12, 2018 at 18:23

1 Answer 1

-2

Have you included the tag in your jsp page

%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.