私は信じられないほど単純なコントローラー/ビューのセットアップを試みてきましたが、それを機能させることができません。私のでは、正常に実行されているという名前web.xml
を定義しました。で、私は設定しました:<servlet>
servlet-context.xml
servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
<...other stuff in here... />
<mvc:annotation-driven />
とりわけ。私の理解では、@
注釈を使用するために必要なのはこれだけです。
私のコントローラーには、次のものがあります。
@RequestMapping(value="/student/{username}/", method=RequestMethod.GET)
public String adminStudent(@PathVariable String username, @RequestParam String studentid) {
return "student";
}
そして私のstudent.jsp
見解では、私は持っています:
<p>This is the page where you would edit the stuff for ${username}.</p>
<p>The URL parameter <code>studentid</code> is set to ${studentid}.</p>
にリクエストするとhttp://localhost:8080/application/student/xyz123/?studentid=456
、期待するビューが表示されますが、すべての変数が空白またはnullです。
<p>This is the page where you would edit the stuff for .</p>
<p>The URL parameter <code>studentid</code> is set to .</p>
自分web.xml
やservlet-context.xml
設定の仕方に問題があるのではないかと思いますが、どこにも犯人が見つかりません。私が見る限り、どのログにも何も表示されません。
更新:私は自分のコードをspring-mvc-showcaseのこの部分に基づいていました:
@RequestMapping(value="pathVariables/{foo}/{fruit}", method=RequestMethod.GET)
public String pathVars(@PathVariable String foo, @PathVariable String fruit) {
// No need to add @PathVariables "foo" and "fruit" to the model
// They will be merged in the model before rendering
return "views/html";
}
...これは私にとってはうまくいきます。この例が機能する理由は理解できませんが、私の場合は機能しません。彼らが何か違うことをしているからですservlet-context.xml
か?
<annotation-driven conversion-service="conversionService">
<argument-resolvers>
<beans:bean class="org.springframework.samples.mvc.data.custom.CustomArgumentResolver"/>
</argument-resolvers>
</annotation-driven>