0

次のスプリングコントローラークラスがあります。

@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>

最後に、ディスパッチャ サーブレット:

<?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>

Jetty サーバーでこの Web アプリを実行し、次の URL を使用してレイアウトを取得します。しかし、サーバーは 404 エラーをスローします。私がやっている間違ったことを特定するのを手伝ってください。

http://localhost:8080/TouchPOSApplicatio/layout

更新: Web ページ要素は適切に表示されますが、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'
4

2 に答える 2

1

TouchPOSApplicatio質問の単なるタイプミスだと思いますか?ここであなたのパターンを理解するのに苦労しています。ブラウザからアクセスできない静的リソースを にマップ/WEB-INF/viewsしたので、うまくいかないと思います。static(と同じレベルで)のように、代わりに通常の webapp フォルダーに入れてみてくださいWEB-INF。次に、設定を次のように変更します。

<mvc:resources mapping="/static/**" location="/static"/>

と入力してアクセスできることを確認できますhttp://localhost:8080/TouchPOSApplication/static/layout.html。これが機能する場合は、静的リソースが正しく構成されています。

編集

css リソースもある場合は、それらのリソースを含むフォルダーを mvc:resource として追加してください。

于 2013-04-19T08:31:33.263 に答える