2015-10-10 21 views
0

其實我最近一直在研究Spring MVC。我在項目中遇到奇怪的行爲。 這是我的分發程序Servlet <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>不能重定向到預期的視圖,得到404

這是我的控制器

@RequestMapping(value="/login",method=RequestMethod.POST) 
public ModelAndView loginThroughCredentials(@ModelAttribute("EmployeeBean") EmployeeBean bean,HttpServletRequest request){ 
    System.out.println("in login"); 
    bean=services.getEmployeeFromLogin(bean); 
    if(bean!=null){ 
     System.out.println("true"); 
     request.getSession(false).setAttribute("employee", bean); 
     return new ModelAndView("homePage"); 
    } 
    return new ModelAndView("../index","error", "Username/Password Not Valid"); 
} 

的問題是,RequestMapping正趕上了登錄URL模式的請求。 並執行method.Method正確執行,但我得到404說

HTTP狀態404 - /EmployeeManagementSystem/WEB-INF/jsp/login.jsp

類型狀態報告

消息/EmployeeManagementSystem/WEB-INF/jsp/login.jsp

description請求的資源不可用。

正如你所看到的,我給了homePage或index作爲視圖。但它們從不被調用控制器將應用程序重定向到login.jsp視圖,而該視圖不存在於我的應用程序中。

你能告訴我爲什麼會發生這種情況嗎?

回答

0

我想你可以提供更多的信息,例如它在「登錄」或「真實」中打印什麼。你的應用程序中是否有任何Spring Security過濾器?你確定你在請求中使用POST嗎?

+0

它在login中打印,如果條目有效且我使用post方法,則爲true。我已經與Spring MVC合作過,從未遇到過這樣的問題。執行是正確的,但在最後ModelAndView採取模式並追加.jsp –