Home > Java > javaTutorial > How to implement jsp page jump in java

How to implement jsp page jump in java

Y2J
Release: 2017-05-06 13:09:12
Original
4767 people have browsed it

This article mainly introduces the implementation method of Spring boot jumping to jsp page. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor to take a look.

I am learning Spring boot, and I have searched a lot about the implementation method of Spring boot jumping to jsp page. I will record it below, and friends who need to know can refer to it. Hope this article is helpful to you.

@Controller annotations

1. Configuration in the application.properties file

# 配置jsp文件的位置,默认位置为:src/main/webapp
spring.mvc.view.prefix=/pages/
# 配置jsp文件的后缀
spring.mvc.view.suffix=.jsp
Copy after login
Copy after login

2. Configuration in the Controller file

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
@Controller
public class UserController {

  @RequestMapping(value = "/index",method = RequestMethod.GET)
  public String toIndex(){
    return "index";
  }
}
Copy after login

3. Start the [main] method in the project App.Java

4. Access the url and access the jsp page: localhost:8080/index

@RestController annotation

1. Configuration in the application.properties file

# 配置jsp文件的位置,默认位置为:src/main/webapp
spring.mvc.view.prefix=/pages/
# 配置jsp文件的后缀
spring.mvc.view.suffix=.jsp
Copy after login
Copy after login

2. Configuration in the RestController file

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
@RestController
public class UserController {

  @RequestMapping(value = "/index",method = RequestMethod.GET)
  public String toIndex(){
    ModelAndView mv = new ModelAndView("index");     
 return mv;  
  }
}
Copy after login

3. Start the [main] method in the project App.java to start

4. Access the url and access the jsp page: localhost:8080/index

Note: application.properties The properties in spring.mvc.view.prefix and spring.mvc.view.prefix are different in the old version of spring-boot and in the new version:
Used in the old version:

spring.view.prefix=/pages/ 
spring.view.suffix=.jsp
Copy after login

Used in the new version:

spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp
Copy after login

[Related recommendations]

1. Java free video tutorial

2. Java implementation Video tutorial on proportional thumbnails of pictures

3. JFinal Online Manual

The above is the detailed content of How to implement jsp page jump in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template