问题是:我的观点是回头客。根据我的viewresolver应该映射到WEB-INF/pages/customer.html。相反,它正在通过调度程序 servlet 并且无法找到客户 html。它给出的错误是:“警告:在名称为'mvc-dispatcher'的DispatcherServlet中找不到带有URI [/SpringMVC/WEB-INF/pages/customer.html]的HTTP请求的映射”
这是我的控制器
@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>