Ho cercato di ottenere un controller/visualizzazione incredibilmente semplice e non riesco a farlo funzionare. Nel mio web.xml
, ho definito uno <servlet>
chiamato servlet-context.xml
, che è in esecuzione ok. In servlet-context.xml
, ho impostato:Spring 3.0.6 MVC @PathVariable e @RequestParam vuoto/vuoto nella vista JSP
<?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 />
tra le altre cose. La mia comprensione è che questo è tutto ciò che è necessario per utilizzare le annotazioni @
.
Nel mio controller, ho:
@RequestMapping(value="/student/{username}/", method=RequestMethod.GET)
public String adminStudent(@PathVariable String username, @RequestParam String studentid) {
return "student";
}
E nella mia student.jsp
vista, ho:
<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>
Quando faccio una richiesta di http://localhost:8080/application/student/xyz123/?studentid=456
, ho la vista mi aspetto, ma tutte le variabili sono vuote o nulle:
<p>This is the page where you would edit the stuff for .</p>
<p>The URL parameter <code>studentid</code> is set to .</p>
Ho il sospetto che sia un problema con il modo in cui sono impostati il mio web.xml
o servlet-context.xml
, ma non riesco a trovare il colpevole da nessuna parte. Non c'è nulla che appare in nessun registro, per quanto posso vedere.
Aggiornamento: stavo basando il mio codice fuori questa parte del 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";
}
... che funziona bene per me. Non riesco a capire perché questo esempio funzioni, ma il mio no. È perché sono doing something different con servlet-context.xml
?
<annotation-driven conversion-service="conversionService">
<argument-resolvers>
<beans:bean class="org.springframework.samples.mvc.data.custom.CustomArgumentResolver"/>
</argument-resolvers>
</annotation-driven>
Devi accettare la tua risposta, poiché è quella giusta. –