相关疑难解决方法(0)

为什么Spring MVC用404响应并报告"在DispatcherServlet中找不到带有URI [...]的HTTP请求的映射"?

我正在编写一个部署在Tomcat上的Spring MVC应用程序.请参阅以下最小,完整且可验证的示例

public class Application extends AbstractAnnotationConfigDispatcherServletInitializer {
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { };
    }
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[] { SpringServletConfig.class };
    }
    protected String[] getServletMappings() {
        return new String[] { "/*" };
    }
}
Run Code Online (Sandbox Code Playgroud)

哪里SpringServletConfig

@Configuration
@ComponentScan("com.example.controllers")
@EnableWebMvc
public class SpringServletConfig {
    @Bean
    public InternalResourceViewResolver resolver() {
        InternalResourceViewResolver vr = new InternalResourceViewResolver();
        vr.setPrefix("/WEB-INF/jsps/");
        vr.setSuffix(".jsp");
        return vr;
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,我有一个@Controllercom.example.controllers

@Controller
public class ExampleController {
    @RequestMapping(path = "/home", …
Run Code Online (Sandbox Code Playgroud)

java spring servlets spring-mvc

82
推荐指数
2
解决办法
5万
查看次数

JSP文件无法在Spring Boot Web应用程序中呈现

我使用嵌入式Tomcat(默认)启动并运行Spring Boot Web应用程序.当它提供JSP文件作为渲染我在控制器中指定的视图的一部分时,JSP不会这样呈现,而是打印出内容.例如:

的index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
    <head></head>
    <body>Test</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在浏览器中呈现视图时,将显示上面的内容,而不是预期的内容:

Test
Run Code Online (Sandbox Code Playgroud)

spring-boot

57
推荐指数
8
解决办法
7万
查看次数

标签 统计

java ×1

servlets ×1

spring ×1

spring-boot ×1

spring-mvc ×1