1

私のコントローラーは現在http://example.com/fix.goのようなものにマップされていますが、もちろん、それはばかげていると思います。http://example.com/fixやhttp://exampleのようなもっと良いものが必要です拡張子のないcom/mmm/fix 。ただし、これを構成しようとすると、機能しません。マッピング全体を理解する上で重要な部分が明らかに欠けています。コントローラーにSpring3.x、tomcat、およびアノテーションを使用しています。

私のweb.xmlは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
        <servlet-name>BooBoo</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>BooBoo</servlet-name>
        <url-pattern>*.*</url-pattern>   <!-- was *.go when it worked -->
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

BooBoo-servlet.xmlは次のとおりです。

<?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/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.foofoo.booboo"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

そして、私のコントローラーの1つは次のように構成されています。

@Controller
public class BangBangController extends BaseController {

            // Used to be fix.go when it worked
    @RequestMapping( value="fix", method=RequestMethod.GET )
    public ModelAndView choose(
            HttpSession session,
            @RequestParam( value="fixId", required=false, defaultValue="-1" ) Integer fixId,
            @RequestParam( value="forkId", required=false, defaultValue="-1" ) Integer forkId 
    )
    throws Exception { ... }
}

http://example.com/mmm/fixのようなURLが機能することを期待して、web.xmlのマッピングを/ mmm / *に変更しようとしましたが、それも機能しませんでした。ブラウザに正しいURLと思われるものを入力すると、「リソース不足」エラーが発生します。

私はここで何を間違えていますか?私にはどのような重要な理解が欠けていますか?作業中の別のプロジェクトで拡張機能なしのものを機能させようとしましたが、そこにも到達できませんでした。私は明らかに何かが欠けています。

4

2 に答える 2

1

問題は、ディスパッチャサーブレットが「。」と一致していることです。初期化。

に変更します

 <url-pattern>/*</url-pattern> 

ただし、静的コンテンツを提供できないため、これも悪いことです。

あなたが本当にすべきことはこれです:

 <url-pattern>/webapp/*</url-pattern> 

ここで、「webapp」はプレフィックスです。すべてのURLにプレフィックスを付ける必要がありますが、それでも静的コンテンツを提供できます。

于 2012-04-08T23:18:17.157 に答える
0

答えは、SpringMVCのものを使用していることを指定せずにspring-servlet.xmlファイルを作成したことです。問題の診断にクリスが助けてくれたことに感謝します。私が試した(しかしこの間違いのために失敗した)いくつかのことが正しいことを確認する必要がありました。

追加した

xmlns:mvc="http://www.springframework.org/schema/mvc"

<mvc:annotation-driven />

そのファイルに、そしてブーム、それは働き始めました。頭を悩ませているのは、「それなしでどうやって機能したのか」ということです。*.goパターンで機能しました。

結果のファイルは次のとおりです。

<?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"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.barbar.foofoo"/>

    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

    <!--
    Declare View Resolver: when view 'view_name' is called (from the Controller), 
    the file '/jsp/view_name.jsp' will be used.
    -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>
于 2012-04-13T03:27:40.540 に答える