Skip to content

when i use jsp,i cant find error.jsp #12802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wangzhihaolighter opened this issue Apr 9, 2018 · 5 comments
Closed

when i use jsp,i cant find error.jsp #12802

wangzhihaolighter opened this issue Apr 9, 2018 · 5 comments

Comments

@wangzhihaolighter
Copy link

`pom.xml

<groupId>com.example.springframework.boot</groupId>
    <artifactId>jsp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>jsp</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Compile -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- Provided -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

my project
image

my aplication.properties

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

when i use

return new ModelAndView("error");

i cant find WEB-INF/jsp/error.jsp
image

when i use

return new ModelAndView("/error");

i can find WEB-INF/jsp/error.jsp
image

in spring-boot source code BasicErrorController ,it use

   @RequestMapping(
        produces = {"text/html"}
    )
    public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
        HttpStatus status = this.getStatus(request);
        Map<String, Object> model = Collections.unmodifiableMap(this.getErrorAttributes(request, this.isIncludeStackTrace(request, MediaType.TEXT_HTML)));
        response.setStatus(status.value());
        ModelAndView modelAndView = this.resolveErrorView(request, response, status, model);
        return modelAndView == null ? new ModelAndView("error", model) : modelAndView;
    }

i guess it is a problem

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 9, 2018
@wilkinsona
Copy link
Member

wilkinsona commented Apr 9, 2018

Sorry, but it's not clear to me what the problem is from a few snippets of code. Can you please describe what you want to be able to do? Once we understand that, we'll be able to tell if your approach is wrong or if your approach is correct and you've found a bug.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Apr 9, 2018
@wangzhihaolighter
Copy link
Author

when i use freemarker or thymeleaf, make a request to an HTTP server
code throw any RuntimeException can be find templates/error.ftl or templates/error.html
application.properties don't have any configuration
but i use jsp ,i create {src/main}/webapp/WEB-INF/jsp folder, application.properties write

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

i use this,can find WEB-INF/jsp/welcome.jsp

new ModelAndView("/welcome");

but i use this or throw any RuntimeException ,i cont find WEB-INF/jsp/error.jsp

new ModelAndView("error");

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 9, 2018
@wilkinsona
Copy link
Member

Both throwing a runtime exception and returning a ModelAndView pointing to error work for me with JSPs (I checked using a war file run with java -jar). If you'd like us to spend any more time investigating this, please spend some time producing a minimal example and step-by-step instructions that reproduce the behaviour you have described.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 9, 2018
@wangzhihaolighter
Copy link
Author

This is my learn demo project linkspring boot learn - jsp

project folder
-src
  -main
    -java
    -resources
    -webapp
      -WEB-INF
        -jsp
          -error.jsp
          -error2.jsp
          -welcome.jsp

code

@GetMapping("/test/error")
    public String error() {
        //cant return error.jsp
        throw new RuntimeException("one error");
    }

    @GetMapping("/to/error")
    public ModelAndView toError() {
        //find WEB-INF/jsp/error.jsp
        //correct
        //return new ModelAndView("/error");

        //error
        //return new ModelAndView("error");

        //spring - BasicErrorController user new ModelAndView("error") cant find error.jsp

        //find WEB-INF/jsp/error2.jsp

        //correct
        //return new ModelAndView("error2");
        return new ModelAndView("/error2");
    }

so,i think BasicErrorController user new ModelAndView("error") error to find error.jsp

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 9, 2018
@wilkinsona
Copy link
Member

Thanks, but that's not quite what I was looking for. I've been able to identify a problem, but I can't tell if it's the problem that you have as you haven't told me what steps to take to reproduce the problem you're seeing. Your sample still looks like an attempt to diagnose a problem rather than to simply reproduce it.

I've opened #12805 for the problem that I've been able to identify. Hopefully this is the same problem as you're seeing. If it's not, please provide the necessary information in this issue and we can re-open it and investigate further.

@wilkinsona wilkinsona removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants