Ashwin Karki
Ashwin Karki

Reputation: 269

Jsp is not detected in project while running the project

I have simple login screen using spring security.And if login is successful,then it is redirect to home.jsp. But, it is saying that,it is unable to locate the Jsp page. While making the new project in maven there was no folder called webapp,so i created myself and I added that webapp in webapp/WEB-INF/view/home.jsp as:

enter image description here

The structure of my project is:

enter image description here

So, login screen appears succesfully and when I login such message is shown:

enter image description here

It says that home.jsp is not found.

My config is::

package com.ashwin.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.ashwin.security")
public class DemoAppConfig {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver=new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }



}

My pom.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ashwin</groupId>
    <artifactId>springsecurity2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>spring-security-demo</name>

    <properties>
        <springframework.version>5.0.2.RELEASE</springframework.version>

       <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <springsecurity.version>5.0.0.RELEASE</springsecurity.version>
    </properties>

    <dependencies>

        <!-- Spring MVC support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- Servlet, JSP and JSTL support -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- spring security config -->
        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>



    </dependencies>

    <!-- TO DO: Add support for Maven WAR Plugin -->
    <build>
      <!--  <finalName>/springsecurity</finalName>-->
        <sourceDirectory>src/main/java</sourceDirectory>


        <resources>


        <resource>

        <directory>src/main/resources</directory>

    </resource>

    </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>

                <plugin>

                <groupId>org.apache.tomcat.maven</groupId>

                <artifactId>tomcat7-maven-plugin</artifactId>

                <version>2.2</version>


                <configuration>

                <path>/spring</path>

            </configuration>

            </plugin>
            </plugins>
        </pluginManagement>
    </build>


</project>

DispatcherServlet class is

package com.ashwin.security.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class SpringMvcDispatcherServletInitializer  extends AbstractAnnotationConfigDispatcherServletInitializer {


     @Override
        protected Class <?> [] getRootConfigClasses() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        protected Class <?> [] getServletConfigClasses() {
            return new Class[] { DemoAppConfig.class  };
        }

        @Override
        protected String[] getServletMappings() {
            return new String[] { "/" };
        }

}

Upvotes: 0

Views: 121

Answers (1)

zpavel
zpavel

Reputation: 969

Your tomcat7-maven-plugin configuration contains <path>/spring</path>. Please replace it and try with <path>/${project.build.finalName}</path>.

Upvotes: 1

Related Questions