页面上线以后,有时候会有特殊的需求,比如不想让别人查看到页面的源码,对于传统的html、jsp页面,我们在页面内写的一些方法都会直接暴露出来,这就需要我们去想办法解决这个问题。
前言
下面就介绍两种思路去解决这个问题,本文以springboot框架为原型
1、利用HttpSecurity授权,赋予js、css、图片、文件等的权限,能让用户在没登录前无法查看
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/images/*.png").permitAll()
.antMatchers("/css/*.css").permitAll()
.anyRequest().authenticated();
}
}
2、直接在单独的页面去禁用F12或者鼠标右键,别忘记页面引入jquery.min.js文件,这样页面就无法F12或者右键查看源码了



