0

I'm working on a spring-boot project which I used JSP files and gives the Whitelabel Error Page. There was an unexpected error (type=Not Found, status=404).

I've put JSP in the /src/main/webapp/pages/ and the path has been given with the application properties.

This has several modules and the main component doesn't include the spring-boot dependancy and it only includes specific modules which needed. Codes inherit from other modules have been used with the spring-boot module since it cannot build separately.

And the particular sub-module doesn't include a spring-boot parent as the parent because the parent has to be defined at that point.

pom.xml (Some of the submodules inherited as dependencies has to remove from the pom due to privacy issues)

<?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">
    <parent>
        <groupId>com.epic.cb</groupId>
        <artifactId>EPICCB</artifactId>
        <version>V1.00</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>M_EOD</artifactId>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.boot.eod.version>1.5.4.RELEASE</spring.boot.eod.version>
        <spring.eod.version>4.3.4.RELEASE</spring.eod.version>
        <apache.tomcat.version>7.0.55</apache.tomcat.version>
        <com.epic.cb.version>V1.00</com.epic.cb.version>
        <sql.version>6.2.1.jre8</sql.version>
        <jquery.version>3.1.1</jquery.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot.eod.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>${spring.boot.eod.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
            <version>${spring.boot.eod.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>${spring.boot.eod.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <version>${apache.tomcat.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>${jquery.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.eod.version}</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>${sql.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>${apache.tomcat.version}</version>
        </dependency>
    <dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </build>
</project>

application.properties

server.port=8589

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

EodController.java

@Controller
public class EodController {

    @Autowired
    EodSchedulerService eodSchedulerService;

    @ResponseBody
    @RequestMapping(value = "/", method = {RequestMethod.GET})
    public String viewMain() {
        return "Hello World !!!";
    }

    @RequestMapping(value = "/viewEODDashboard", method = {RequestMethod.GET})
    public String viewEODDashboard() {
        return "eodTaskDashboard";
    }

    @RequestMapping(value = "/executeEodTasks", method = {RequestMethod.GET})
    @ResponseStatus(code = HttpStatus.OK)
    public void approveEODDashboard() {
        eodSchedulerService.executeScheduledTasks();
    }
}

EodStartup.java

@SpringBootApplication
@ComponentScan("com.epic.cb.*")
public class EodStartup {

    public EodStartup() {
        //default constructor
    }

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

File Structure

├── src
     ├── main
     |    ├── java
     │    │   └── com
     │    │        └── epic
     │    │             └── cb
     │    │                  └── eod
     │    │                       ├── EodStartup.java
     │    │                       └── controller
     │    │                              └── EodController.java 
     |    |
     │    ├── resources
     │    |     └── application.properties
     │    └── webapp
     │          └── WEB-INF
     │                 └── pages
     │                       └── eodTaskDashboard.jsp

Following are a few links of what I've referred:

  1. Why do I always get Whitelabel Error Page with status "404" while running a simple Spring Boot Application
  2. Spring Boot JSP 404.Whitelabel Error Page
  3. Tomcat-embed-jasper added but jsp pages Whitelabel 404 Error
  4. Getting whitelabel error page when running springboot application etc..

I want to solve this with JSP. (since it has several other options ex: Thymeleaf)

Thank you in Advance!

namilaW
  • 31
  • 2
  • Hi could you specify the url that you are trying to resolve ? I could see that only viewEODDashboard() method is resolving a view, of the other two one is returning only data and the other is returning nothing at all apart from status code success. – Ananthapadmanabhan Oct 03 '19 at 07:27
  • I'm trying to resolve the "viewEODDashboard" url. – namilaW Oct 03 '19 at 07:39
  • JSP only works with war packaging and has severe limitations (see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations). That being said your web app shouldn't be under `java` but diurectly in `src/main`. Looking closer at your file structure it looks borked. The paths should be `src/main/java`, `src/main/resources` and `src/main/webapp`. Currently looks like you aren't following default maven conventions. Finally let Spring Boot manage your dependencies (include the bom) and use the `spring-boot-maven-plugin` to build a proper war/jar. – M. Deinum Oct 03 '19 at 08:11
  • Sorry, @M.Denim I've posted the incorrect, corrected it. My original webapp and resources come under the main. And also tried the spring-boot-maven-plugin also. – namilaW Oct 03 '19 at 10:37
  • A lot of great answers that works [here](https://stackoverflow.com/questions/29782915/spring-boot-jsp-404). – kparobo Oct 10 '19 at 19:06

1 Answers1

0

Try providing this dependency with scope as 'provided', if you are using embedded tomcat :

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

For JSP files, put in src/main/webapp/WEB-INF/pages/ and put resources under /src/main/resources/ Springboot expects this hierarchy to be maintained , and from your project structure it is not correct.

Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39
  • Still, the **Whitelabel Error Page** remains with the _There was an unexpected error (type=Not Found, status=404). No message available_ – namilaW Oct 03 '19 at 07:52
  • move your webapp folder to sc/main – Ananthapadmanabhan Oct 03 '19 at 08:06
  • Like @M. Denium said you should build the war or jar using the springboot maven plugin itself. Also jsp only works properly with war packaging due to tomcat constraints. Try using springboot maven plugin.The resultant war that you might be getting now after build may not have the jsp's included. – Ananthapadmanabhan Oct 03 '19 at 09:12
  • I've tried the springboot maven plugin also but remain the same. – namilaW Oct 03 '19 at 10:42