【问题标题】:jsp is not rendering on requested urijsp 未在请求的 uri 上呈现
【发布时间】:2018-08-16 15:28:15
【问题描述】:

点击 localohst: 而不是我的welcome.jsp,我得到“欢迎”

这是我的控制器:

 @RestController
    public class WelcomeController {
    // inject via application.properties
    @Value("${welcome.message:test}")
    private String message = "Hello World";

    @RequestMapping("/")
    public String welcome(Map<String, Object> model) {
        model.put("message", this.message);
        return "welcome";
    }

启动应用程序:

public class SpringBootWebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootWebApplication.class);
    }

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

application.properties:

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

【问题讨论】:

  • 您使用的是嵌入式tomcat还是其他服务器?
  • 我正在使用嵌入式 tomcat org.springframework.bootspring-boot-starter-tomcat 提供

标签: java spring spring-mvc jsp spring-boot


【解决方案1】:

您的WelcomeController 是休息控制器,使其成为带有@Controller 注释的普通控制器,如本例所示。 https://medium.com/@milansavaliyaz/spring-boot-hello-world-example-with-jsp-view-7ffed2ae931d

【讨论】:

  • 谢谢,但我收到错误:javax.servlet.ServletException: 无法解析名称为“dispatcherServlet”的 servlet 中名称为“welcome”的视图
  • 你的jsp的位置是什么?你的 jsp 应该在 /WEB-INF/jsp/ 并且它的名字应该是 welcome.jsp
  • 是的,在同一个文件夹中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-06
相关资源
最近更新 更多