示例项目

新版即时通讯项目

1
~/workspace/jiange/git/SessionArchives

集成jsp需要引入的pom文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

<!-- servlet依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>

pom内的build脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
<!--注意此次必须要放在此目录下才能被访问到 -->
<targetPath>META-INF</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>

新建webapp包对应引入jsp页面和jstl文件,如图:

增加springmvc的配置类

增加视图解析器组件和放开静态资源的访问路径.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.swordgate.sessionarchives.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@Slf4j
public class SpringMVCConfig implements WebMvcConfigurer {

@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}

启动springboot项目,如果能正常访问到jsp页面,并也能访问到js、css即可,如图:

参考博客:

https://blog.csdn.net/u010459738/article/details/106274939 –解决访问不到静态资源内容

https://blog.csdn.net/chuan8898439/article/details/82958903 –解决jsp需要引入servlet框架内容

国际化可以参考的内容说明(待整理)

https://developer.aliyun.com/article/791330

https://www.jianshu.com/p/e2eae08f3255

https://blog.csdn.net/qq_22075913/article/details/108547481

https://qiushurong.github.io/2014/08/28/struts-i18n/

https://blog.csdn.net/allway2/article/details/123326943

https://www.runoob.com/jsp/jsp-internationalization.html

https://blog.csdn.net/qq_36420790/article/details/82465545 –jsp动态引入jstl标签库