2015-11-03 11 views
6

के लिए जेएसपी पर रीडायरेक्ट करता है मैं अंगुलरजेएस प्रोजेक्ट के लिए स्प्रिंग एमवीसी का उपयोग कर रहा हूं।स्प्रिंग एमवीसी विशिष्ट यूआरएल

मैं "/ rest/*" से पहले यूआरएल से जेएसओएन की सेवा कर रहा हूं। सभी जेएसपी फ़ाइलों को सीधे एक्सेस किया जाता है और कोणीय-जेएस का उपयोग करके रूटिंग को संभाला जाता है।

मुझे jsp फ़ाइलों तक पहुंचने से पहले कस्टम सत्यापन करने की आवश्यकता है। बाकी यूआरएल के लिए (url "/ rest/*" के साथ prefixed), मेरे पास पहले से ही फ़िल्टर हैं।

मैं प्रेषक-सर्वलेट को कैसे कॉन्फ़िगर कर सकता हूं जैसे वसंत नियंत्रक द्वारा सत्यापन किए जाने के बाद सभी जेएसपी फ़ाइलों को एक्सेस किया जाता है।

web.xml

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

डिस्पैचर-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?> 
<!-- was: <?xml version="1.0" encoding="UTF-8"?> --> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/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"> 

    <context:component-scan base-package="com.gauti" /> 
    <mvc:annotation-driven /> 
</beans> 

उत्तर

6

आप हमेशा अपने डिस्पैचर सर्वलेट को एक से अधिक यूआरएल मैप कर सकते हैं।

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
    <url-pattern>/non-rest/*</url-pattern> 
    </servlet-mapping> 

<servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 
       classpath:spring-config/dispatcher-servlet.xml 
      </param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

सत्यापन आप अपने विभिन्न url प्रतिमानों के लिए MVC इंटरसेप्टर कॉन्फ़िगर कर सकते हैं के लिए। उदाहरण के लिए

<mvc:interceptors> 
     <mvc:interceptor> 
      <mvc:mapping path="/**"/> 
      <bean id="localeChangeInterceptor" 
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
      <property name="paramName" value="j_lang" /> 
      </bean> 
     </mvc:interceptor> 
</mvc:interceptors> 

और अपने कोणीय संसाधनों के लिए एक आम नियंत्रक कॉन्फ़िगर करें:

@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); 
    } 

} 
संबंधित मुद्दे