【问题标题】:Unable to print JSP from spring controller but result is printing in console无法从 spring 控制器打印 JSP,但结果是在控制台中打印
【发布时间】:2019-07-19 16:17:41
【问题描述】:

[代码]

@Controller

公共类 AWSCostAndUsageClientController {

@Autowired
AWSCostAndExplorerService costExplorerService;

@RequestMapping("/aws")
public String cost(Model model) throws JsonProcessingException {

    List<ResultByTime> obj = costExplorerService.costUsage();


    ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = writer.writeValueAsString(obj);
    System.out.println(json);

    model.addAttribute("costData", json);
    return "cost";
}

}

WARN 3864 --- [nio-8081-exec-1] oswsrResourceHttpRequestHandler:带有“WEB-INF”或“META-INF”的路径:[WEB-INF/view/cost.jsp]强>

我无法打印 jsp。在浏览器中它正在打印

白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2019 年 2 月 26 日星期二 12:17:40 IST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息

我正在开发 Spring Boot 项目。

application.properties

spring.mvc.view.prefix=/WEB-INF/view/

spring.mvc.view.suffix=.jsp

【问题讨论】:

    标签: spring-boot spring-mvc jsp


    【解决方案1】:

    我的问题已经解决了。我必须添加jasper和jstl的依赖项。

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 2021-02-17
      • 1970-01-01
      相关资源
      最近更新 更多