2016-09-26 78 views
0

我在類級別爲某些視圖(jsp)添加了@RequestMapping註釋。當我嘗試使用正確的URL映射訪問這些頁面時,Pages顯示在頁面上但無法正確呈現,並且無法加載.js和.css文件。在瀏覽器中,我得到了follwing錯誤。 GET 404(Not Found) 在服務器日誌中,我收到以下消息。 org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在帶有名稱的DispatcherServlet中使用URI [/ccb/invoice/webjars/adminlte/2.3.3/plugins/iCheck/icheck.min.js]發現的HTTP請求沒有映射「彈簧調度」。 不知道爲什麼事情開始發生,儘管Servlet配置文件中的靜態資源映射非常好,並且它對那些在類級別沒有@requstmapping註釋的頁面加載。在類級別添加@REQUESTMAPPING註釋後無法加載CSS和JS文件

您能否讓我知道我犯了什麼錯誤。

@Controller @RequestMapping("/invoice") @SessionAttributes("ListOrderItems") public class InvoiceController { 
    @RequestMapping(value = "/index", method = RequestMethod.GET) 
    public ModelAndView adminPage() { 
     System.out.println("Im in /Index** Mapping"); 
     String username; 
     Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
     username = auth.getName(); //get logged in username 
     username.toUpperCase(); 
     // Logic to build menue based on the Role of the user. 
     HashMap hm = new HashMap(); 
     OrderItems od = new OrderItems(); 
     ModelAndView model = new ModelAndView(); 
     model.addObject("usr", username); 
     //Set the object for Menue Links on the Page 
     model.addObject("mnue", hm); 
     model.setViewName("index"); 
     model.addObject("odi",od); 
     return model; 

    } } 


Dispatcher Servlet configuration file: <mvc:resources mapping="/webjars/**" location="/webjars/" /> 
    <mvc:resources mapping="/resources/**" location="/resources/" /> 
    <mvc:annotation-driven/> 
    <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
> 
     <property name="prefix"> 
      <value>/WEB-INF/jsp/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 

回答

0

嘗試在分發程序Servlet添加的xmlns

xmlns="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd 

然後

<resources mapping="/resources/**" location="/resources/" /> 
    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean>