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.
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>