我正在使用Maven和Spring,而我的EL似乎并没有使用我的JSP。我最终看到了这个结果。
JSP工作,GET和POST方法似乎运行正常。它似乎没有认识到EL。我也尝试过使用JSTL,但EL和JSTL表达式都被读作静态文本。我一直在尝试我能找到的所有依赖项组合,但无济于事。如果有人在遇到问题之前请帮忙。
的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);
}
}
配置文件
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
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>
答案 0 :(得分:-2)
您是否已将标记包含在jsp页面中
%@ taglib uri =&#34; http://java.sun.com/jsp/jstl/core"前缀=&#34; C&#34; %