2

This is a controller of springboot, I want to write a function to redirect to an html page, but it always responded with 404, and here is the code and properties. '

@Component

@Controller

@RequestMapping("/Weixin")

public class KindlePocketController {

private static final long serialVersionUID = 1L;

@Autowired
private TextBookInfoSearchService searchService;

@RequestMapping("/homepage")
public String toIndex() {
    System.out.println("redirecting to homepage...");
    return "index";
}
}

' application.properties '

spring.view.prefix=/WEB-INF/views/

spring.view.suffix=.html

'

the program can get into the function and output is ok. And index.html is in this path:/WEB-INF/views/index.html. Is there any else configurations ? Thanks a lot

9
  • What url you are trying? As per your configuration you should see index.html when u hit http://...contextPath/Weixin/homepage. Commented May 15, 2016 at 8:48
  • @SanjayRawat the url is localhost:8080/Weixin/homepage,but it responsed 404 Commented May 15, 2016 at 8:51
  • the atComponent is redundant. You only need atController. Not sure if that is causing the problem. Commented May 15, 2016 at 8:51
  • Is there any particular reason you are not using the Spring Boot default location? src/main/resources/templates Commented May 15, 2016 at 8:53
  • @ccit-spence thanks,I tried this but it did not work Commented May 15, 2016 at 8:56

2 Answers 2

2

You got the incorrect configuration, try this:

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.html

Its spring.mvc.view.* and not spring.view.*.

PS: Use the Intelisense provided by STS or InteliJ.

Sign up to request clarification or add additional context in comments.

Comments

0

This mapping @RequestMapping("/Weixin") maps to URL with that name: Example: localhost:8080/Weixin

Second you have another mapping@RequestMapping("/homepage") which maps to URL: Example2: localhost:8080/Weixin/homepage

You would be redirected to index page whenever you try to access that URL of Example2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.