当前位置: 首页 > 知识库问答 >
问题:

Spring Boot-JSP视图未找到

谢叶五
2023-03-14

我正在寻找如何使用spring Boot运行jsp。我试了几次,但还是没找到。

然后我进行了以下配置:

<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>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-undertow</artifactId>
   </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.17.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.8</version>
        </dependency>

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
  </dependency>

   <!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
     <dependency>
          <groupId>org.apache.pdfbox</groupId>
          <artifactId>pdfbox</artifactId>
          <version>2.0.1</version>
      </dependency>

   <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
       <dependency>
           <groupId>com.itextpdf</groupId>
           <artifactId>itextpdf</artifactId>
           <version>5.0.6</version>
        </dependency>

      <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
       <dependency>
         <groupId>org.glassfish.jersey.core</groupId>
         <artifactId>jersey-server</artifactId>
         <version>2.17</version>
       </dependency>

        <!--the SL4J dependencies.  -->
        <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-api</artifactId>
              <version>1.7.19</version>
        </dependency>
        <dependency>
              <groupId>org.apache.logging.log4j</groupId>
              <artifactId>log4j-slf4j-impl</artifactId>
              <version>2.5</version>
        </dependency>

        <!-- the Log4J 2 dependencies. -->   
        <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-api</artifactId>
             <version>2.5</version>
        </dependency>
        <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-core</artifactId>
             <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>2.5</version>
       </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <!-- Spring security -->
          <dependency>
              <groupId>org.springframework.security</groupId>
               <artifactId>spring-security-web</artifactId>
               <version>4.0.3.RELEASE</version>
          </dependency>

          <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.3.RELEASE</version>
         </dependency>

           <!-- Spring Security JSP Taglib -->
         <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>4.1.4.RELEASE</version>
         </dependency>

        <!-- To compile JSP -->
        <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- jstl for jsp page -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

    </dependencies>
 @Configuration
    @EnableWebMvc
    @ComponentScan
    public class MvcConfig  extends WebMvcConfigurerAdapter{
        @Override
        public void configureViewResolvers(ViewResolverRegistry registry) {
            InternalResourceViewResolver resolver = new InternalResourceViewResolver();
            resolver.setPrefix("/WEB-INF/Views/");
            resolver.setSuffix(".jsp");
            resolver.setViewClass(JstlView.class);
            registry.viewResolver(resolver);
        }
     @Override
        public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/login").setViewName("login");
    }

-class WebSecurityConfig :

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled=true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
protected void configure(HttpSecurity http) throws Exception {
     http.authorizeRequests()
         .antMatchers("/Users/**").access("hasRole('ADMIN')")
          .anyRequest().authenticated()
          .and()
            .formLogin().loginPage("/login").permitAll()
            .defaultSuccessUrl("/Acceuil")
          .and()
            .logout().logoutSuccessUrl("/login?logout") 
           .and()
           .exceptionHandling().accessDeniedPage("/403")
          .and()
            .csrf();
}
}
@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
public class AppsApplication extends SpringBootServletInitializer{

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(AuditConfigurationApplication.class);
        }

    public static void main(String[] args) {
        SpringApplication.run(AuditConfigurationApplication.class, args);



    }
}
spring.mvc.view.prefix= /WEB-INF/Views/
spring.mvc.view.suffix= .jsp

PageNotFound:未找到名为“DispatcherServlet”的DispatcherServlet中URI[/app/WEB-INF/jsp/login.jsp]的HTTP请求映射

jsp页面可以在以下站点找到:src/main/webapp/WEB-INF/jsp/login.jsp

编辑1:

<beans xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.SSC"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         id="WebApp_ID" version="3.1">
     <display-name>JSP</display-name>
    <welcome-file-list>
        <welcome-file>login.html</welcome-file>
        <welcome-file>login.htm</welcome-file>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    <!-- Spring Boot Servlets -->
    <servlet>
        <servlet-name>SpringBootWebXmlServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcher.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>SpringBootWebXmlServlet</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>
</web-app>
Circular view path [login]: would dispatch back to the current handler URL [/App/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

感谢您帮助我在服务器中运行login.jsp页面。

共有1个答案

金飞
2023-03-14

我没有看到完整的pom.xml,但对我有效的方法(根据注释中提到的Spring JSP限制)是将打包从JAR改为WAR。

<packaging>war</packaging>
 类似资料:
  • 我正试图按照本教程将thymeleaf添加到springboot应用程序中,但我似乎无法让它工作。辅导的:http://spr.com/part-2-adding-views-using-thymeleaf-and-jsp-if-you-want/ 当我在LoginController中使用@RestController启动应用程序时,我能够让springstart正常工作,但是当我将@RestC

  • 问题内容: 我对laravel视图有问题,找不到路由函数,我做了作曲家dumpautoload但没有使用ArticleController.php InvalidArgumentException 问题答案: 当Laravel在您的应用程序中找不到视图文件时,就会发生这种情况。确保你有一个文件名为:或者你在目录中。 请注意,在调用时Laravel将执行以下操作: 对于Laravel,它将查找文件:

  • Im my routes.php我有以下内容: 当我的数据库还没有表,我想进行php artisan迁移时,结果是:SQLSTATE[42S02]:找不到基表或视图:1146表“ae_dev.categories”不存在 我的迁移文件: 我认为Laravel托盘从routes.php调用类别,想做选择或某种想法,所以我想运行创建类别表的迁移,但上述错误是在... 我怎样才能解决这个问题?

  • 我正在尝试使用spark sql运行一个基本的java程序 如果有人能给我指出一些在斯巴克-sql(斯巴克-2.1.1)上可以阅读的好材料,那也太好了。我计划使用火花来实现ETL,连接到MySQL和其他数据源。 异常在线程"main"org.apache.spark.sql.分析异常:未找到表或视图:;第1行pos 21;

  • 我在尝试执行此代码时遇到以下错误。 java.lang.IllegalArgumentException:在“com.app.aggregatorappaconfiguration”上找不到ConfigurationProperties注释。在org.springframework.util.assert.NotNull(assert.java:115)~[spring-core-4.3.2.re

  • 我使用springboot和maryadb数据库进行训练。当我测试数据恢复时,我在邮递员中收到这样一条消息: 。我在复制粘贴中尝试了几个教程,我总是有相同的消息。我也会把控制台中的消息。提前谢谢你的帮助。 控制器 服务 回应的 模型 应用属性 安慰