java - springmvc 路径匹配
PHP中文网
PHP中文网 2017-04-18 09:35:00
0
1
199

dispatcher拦截格式设置为*.do
filter格式设置为abc(工程名)/*
前端是spa的设计,所以现在出现一个问题,前端自己跳转的url是/abc/a这种样式的,没有后缀,因而如果刷新一下就会404,暂时性的方法是把唯一的页面配置到error404里去,就是本质上是404,但是设置跳到了正确页面,可是总是觉得不是正确的做法。
尝试了一下另一个方法,把dispatcher拦截格式设置为/,然后将静态资源配置成多个default,filter也改成.do,这样做的话,再设置一个通用的控制器,requestmapping为"/**",将接到的请求直接转到唯一的页面,这样出现的问题是,接收不到/abc/a这样的请求,只能将requestmapping改成/abc/a的样式,才可以接收到请求。不是很明白是哪里错了,而且,就算可以请求到,前端的页面的自跳转,也需要我写多个控制器,感觉不是很科学。
希望有spa经验的前辈可以说下是怎么处理前端页面跳转的。
(前端自己控制页面的跳转,后台通过ajax请求和前端交互数据,但是前端的页面跳转需要后台帮忙返回个页面,否则404)
补充:设置的filter,使用的是HandlerInterceptorAdapter,配置了mappingurl为*.do,但是会把诸如/abc(工程名)/a 这样的url也过滤进去。不知问题何在

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
小葫芦
自己测试了,给个自己的判断,如果有错误,欢迎指出
拦截器的mapping,应该还是在dispatcher的基础上做的,即:只有符合了dispatcher配置的url规范,才能被拦截器去拦截进行判断。依据是:我修改了配置的servlet-mapping,从/改成*.do 以后,拦截器还是保留*.do,但是这时,就不会再拦截没有后缀的url请求了;但是如果servlet-mapping 改回/的话,拦截器配置urlmapping不变,还是*.do,可是拦截器还是会拦截所有的url请求,包括*.do和普通无后缀的url请求。
7.27最新解决办法

Correction to my answer. Previously, I used the method of injecting interceptors. Under the DefaultAnnotationHandlerMapping configuration, I used the <property name="interceptors">, <ref bean="myInterceptor"> method to inject the interceptor. Injection, therefore, even if I configure the intercepted url path in the myinterceptor bean, he will intercept all paths, which is the reason for the failure. The solution is to use <mvc:interceptors> to configure, then write <mvc:interceptor> in it, and configure the paths that need to be intercepted. In this way, paths that I don’t need will not be intercepted. At this point, the problem is solved. , record it. | Add code

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!