問題是:我以客戶爲回報。根據我的viewresolver是應該映射到WEB-INF/pages/customer.html。相反,它是通過調度程序servlet進行的,無法找到客戶的html。它給出的錯誤是:「警告:沒有映射找到具有URI [/SpringMVC/WEB-INF/pages/customer.html]中的名稱爲'mvc-dispatcher'的HTTP請求的映射'」Spring MVC:調度員映射到錯誤視圖
這是我的控制器
@Controller
public class CustomerController implements BeanFactoryAware {
private Customers customers;
/*public String getCustomer(@RequestParam String name) {
//ApplicationContext context = new FileSystemXmlApplicationContext("/WEB-INF/springapp-servlet.xml");
//Customers customers = get
System.out.println("In Controller");
return "customer";
}*/
@RequestMapping(value="/form")
public String getCustomer(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("In Customer Controller");
return "customer";
}
@Override
public void setBeanFactory(BeanFactory context) throws BeansException {
// TODO Auto-generated method stub
customers = (Customers)context.getBean("customers");
//System.out.println(customers);
}
}
這是我的web.xml
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd「>
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml,/WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
這是我的dispatcher.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.html</value>
</property>
</bean>
我試過改變/ *到/也還是同樣的問題。我有奇怪的行爲。每當我將所有htmls重命名爲jsps時,它工作正常,但將擴展名更改爲htmls會給我帶來問題。在轉換爲jsp時,我只是在internalviewresolver中將後綴屬性更改爲jsp。感謝Biju – Gaurav 2012-08-06 05:44:22