Skip to content

An example of Spring Boot application that uses an embedded tomcat and jsp.

Notifications You must be signed in to change notification settings

luwojtaszek/springboot-jsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

springboot-jsp

An example of Spring Boot application that uses an embedded tomcat and jsp.

Use JSP in your current Spring Boot project

  1. Add required dependencies:
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency><!-- Optional, use this only when you need spring security taglibs -->
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-taglibs</artifactId>
</dependency>
  1. Add view prefixes in application properties (yaml example below)
spring:
  mvc:
    view:
      prefix: /WEB-INF/
      suffix: .jsp
  1. Configure view resolver:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Value("${spring.mvc.view.prefix}")
    private String prefix;

    @Value("${spring.mvc.view.suffix}")
    private String suffix;

    /**
     * Configures view resolver for jsp views.
     */
    @Bean
    public InternalResourceViewResolver setupViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix(prefix);
        resolver.setSuffix(suffix);
        resolver.setViewClass(JstlView.class);
        return resolver;
    }
}
  1. Create jsp views in src/main/webapp/WEB-INF/ directory.

How to run this application

Extract project

Extract project in some location on your local machine.

Build application

Go to the project location:

cd /path/to/project/location

Build project with maven by executing command:

./mvnw clean install

Start application

Execute .jar file:

java -jar target/rxjava2-simultaneous-tasks-0.0.1-SNAPSHOT.jar

By default application should be accessible under localhost:8080.

There is one endpoint which returns simple jsp home page.

About

An example of Spring Boot application that uses an embedded tomcat and jsp.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages