我有以下弹簧控制器类。
@Controller
public class LayoutController {
@RequestMapping(value = "/layout", method = RequestMethod.GET)
public String ShowLayout(){
return "redirect:/views/layout.html";
}
}
这是我的通用配置 xml。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- COMMON CONFIGURATIONS -->
<mvc:annotation-driven/>
<tx:annotation-driven/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".html" />
<!-- Annotations based Configuration -->
<context:annotation-config />
<mvc:resources mapping="/*" location="/WEB-INF/views/" />
<!-- Components Auto-Detection (Backend) -->
<context:component-scan base-package="com.jkcs.touchpos" use-default-filters="false" >
<!-- Types annotated by Spring Managed, Controller and Transactional, or by an annotation that itself is
annotated by SpringManaged, Controller, Transactional -->
<context:include-filter type="annotation" expression="com.jkcs.touchpos.platform.annotations.SpringManaged"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.transaction.annotation.Transactional"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
</beans>
这是我的 mvc-config xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
</beans>
这是我的 web.xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TouchPOS</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
最后是调度程序 servlet:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- SPECIFIC CONFIGURATIONS -->
<import resource="springConfigurations/common-config.xml"/>
<import resource="springConfigurations/mvc-config.xml"/>
</beans>
当我在码头服务器上运行此 Web 应用程序时,我使用以下 URL 来获取布局。但是服务器会抛出 404 错误。请帮我找出我在做的错误的事情?
http://localhost:8080/TouchPOSApplicatio/layout
更新:网页元素显示正确但没有 CSS。控制台打印了以下错误。
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/style/style.css] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/style/jquery.custom-scrollbar.css] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery-1.9.1.min.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery.colorbox.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery.touchSwipe.min.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/functions.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/dragscrollable.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery-ui.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/style/colorbox.css] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery.colorbox.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/functions.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/jquery.touchSwipe.min.js] in DispatcherServlet with name 'dispatcher'
Apr 19, 2013 2:17:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TouchPOSApplication/js/dragscrollable.js] in DispatcherServlet with name 'dispatcher'