微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring MVC重定向到特定URL的jsp

我正在为AngularJS项目使用Spring MVC.

我从前缀为“/ rest / *”的网址中提供JSON.直接访问所有jsp文件,并使用angular-js处理路由.

我需要在访问jsp文件之前进行自定义验证.对于其他网址(以“/ rest / *”为前缀的网址),我已经有了过滤器.

如何配置dispatcher-servlet,以便在弹簧控制器完成验证后访问所有jsp文件.

web.xml中

<servlet-mapping>
    dispatcherservlet-mapping>

调度员servlet.xml中

spring-beans-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    
最佳答案
您始终可以将多个URL映射到调度程序servlet.

 <servlet-mapping>
     dispatcherservlet-mapping>

 dispatcherdispatcherServlet
      aram>
            aram-name>contextConfigLocationaram-name>
            aram-value>
                classpath:spring-config/dispatcher-servlet.xml
            aram-value>
        aram>
      

用于验证
您可以为不同的url模式配置mvc拦截器.例如

aramName" value="j_lang" />
          

并为角度资源配置一个通用控制器:

@Controller
@RequestMapping("/ng")
public class AngularResourcesController {

    @RequestMapping(value = "/**",method = RequestMethod.GET)
    public ModelAndView process(HttpServletRequest request) {
        String pageName = null;
        //create your custom jsp URL,modify accordingly to your jsp location. 
        pageName =request.getRequestURL().toString();
        //forward to internal jsp.
        return new ModelAndView(pageName);
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐