我使用`Spring Boot http://localhost:8080/vehicleApp创建了一个应用程序,我的JSP文件的内容被打印而不是预期的输出。
以下是代码:
VehicleApplication.java(主要类)
package com.Vehicle.prototype;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class VehicleApplication {
public static void main(String[] args) {
SpringApplication.run(VehicleApplication.class, args);
System.out.println("Vehicle Application started");
}
}
MvcConfig.java
package com.vehicle.prototype.config;
@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
VehicleController.java
package com.vehicle.prototype.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class VehicleController {
@RequestMapping(value="vehicleApp")
public String home(Model model) {
model.addAttribute("greetings", "hello");
return "vehicleApp";
}
}
的src /主/ web应用/ WEB-INF / JSP / vehicleApp.jsp (这些相同的内容按原样打印)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
<h1>${greetings}</h1>
</body>
</html>
请让我知道我错过了什么?
谢谢