如何配置JSP URL是spring boot嵌入tomcat?

时间:2017-05-10 20:17:51

标签: java spring jsp spring-mvc spring-boot

正在开发应用程序,其中我的所有jsp都在目录/ WEB-INF / default / pages /中,而下面是我的application.properties

server.port=${server.port}
server.contextPath=/myapplication
spring.mvc.view.prefix=/WEB-INF/default/pages/
spring.mvc.view.suffix=.jsp

当我启动我的应用程序时,我需要点击以下URL以查看登录页面。但这不是我想要的。

http://localhost:8081/myapplication/default/pages/login.jsp

我想查看下面的网址以获取登录页面。

http://localhost:8081/signin

我为此做了一些改变,但没有任何效果。

问题1: 如果我更改为server.contextPath = /或从应用程序属性中删除它,我可以在

获取登录页面
http://localhost:8081/default/pages/login.jsp

但问题是我无法在页面之间重定向时获取会话变量。 request.getSession(false)返回null。

问题2:

我也无法将登录页面映射到URL。

<servlet>
    <servlet-name>login123</servlet-name>
    <jsp-file>/WEB-INF/default/pages/login.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>login123</servlet-name>
    <url-pattern>/signin</url-pattern>
</servlet-mapping>

即使这样也行不通。

安全配置:

@Configurable
@EnableWebSecurity
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//@ComponentScan(basePackageClasses={EpPermissionValidator.class})
// Modifying or overriding the default spring boot security.
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final Log logger = LogFactory.getLog(WebSecurityConfig.class);
    @Override
    public void configure(WebSecurity web) throws Exception {
        logger.info("configure() method started..");
        try {
            web.ignoring()
            // ignoring the "/", "/index.html", "/app/**", "/register",
            // "/favicon.ico"
            .antMatchers("/bus/refresh","/monitoring","/**/*.css","/**/*.js","/**/*.map","/**/*.json", "/login","/signin","/default/pages/login.jsp","/css/**","/ext/**","/js/**","/resources/**","/script/**","/Singapp/**","/style/**","/favicon.ico","/UtilController", "/invalidateSession");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Error occured at.."+ e);
        }finally {
            logger.info("configure() method ended..");
        }
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        logger.info("configure() method started..");
        try {
            http
            // starts authorizing configurations
            .authorizeRequests()
            // authenticate all remaining URLS
            .anyRequest().fullyAuthenticated().and()
            // adding JWT filter
            .addFilterBefore(new MyFilter(), UsernamePasswordAuthenticationFilter.class)
            // enabling the basic authentication
            .httpBasic().and()
            // configuring the session as state less. Which means there is
            // no session in the server
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            // to allow iframe from the same orgin
            .headers().frameOptions().sameOrigin().and()
            // disabling the CSRF - Cross Site Request Forgery
            .csrf().disable();          
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Error occured at.."+ e);
        }finally {
            logger.info("configure() method ended..");
        }
    }

}

0 个答案:

没有答案