Ajax Rest Call all'app Web con primavera 3 e tessere 2
-
30-10-2019 - |
Domanda
Ho un WebApp che è costruito utilizzando Spring 3 e Liles 2 (non riposante). Sto usando URLBasedViewResolver per visualizzare le visualizzazioni
il mio servizio-servizio.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.xxx.xxxx.xxxxx.web.controller" />
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
</beans>
My Tiles.xml
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/views/layout.jsp">
<put-attribute name="header" value="/WEB-INF/views/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp" />
</definition>
<definition name="welcome" extends="base.definition">
<put-attribute name="body" value="/WEB-INF/views/welcome.jsp" />
</definition>
</tiles-definition>
Ora il mio problema è: ho un modulo dinamico sul lato client generato al volo (usando JavaScript) in base alle opzioni degli utenti come, se un'opzione viene scelta dalla prima casella a discesa, quindi carico il resto del modulo e così via. Per il mio primo menu a discesa non ho problemi, perché quelle opzioni sono costanti. Ma per la mia seconda scelta di menu a discesa ho bisogno di caricare informazioni specifiche ed è disponibile solo sul server, quindi ho pensato di effettuare una chiamata AJAX (chiamata riposante), quindi ho creato un controller come questo
Il mio controller riposante:
@Controller
public class UtilsController {
private WebAdministration admin;
public UtilsController() throws WebAdministrationException {
this.admin = WebAdministration.getInstance();
}
@RequestMapping(value="/aaaa/${site}/${type}", method=RequestMethod.GET, headers="Accept=text/xml, application/json")
public @ResponseBody List<String> getRemoteSites(@PathVariable("site") String site, @PathVariable("type") String type) {
List<String> remoteSites = null;
Config config = (Config) admin.getImplemantationData().get(Implementations.IMPL);
if (type.equals(Config.PERSISTENCE)) {
remoteSites = config.getRemoteSites().get(site).getNewRemoteSites();
}
else if (type.equals(Config.OLD)) {
remoteSites = config.getRemoteSites().get(site).getOldRemoteSites();
}
return remoteSites;
}
}
la mia chiamata ajax:
<script type="text/javascript">
function getRemoteSites(site, type) {
$.getJSON('/aaaa/'+site+'/'+type, {
ajax : 'true'
}, function(data) {
var len = data.length;
for ( var i = 0; i < len; i++) {
document.write('<form:checkbox path="remoteSites" value="' + valueArray[i] + '" />');
}
});
};
</script>
E la mia richiesta AJAX non riesce con 404 - nessuna mappatura trovata.
Come posso far funzionare il mio URL di riposo. So che ho bisogno di un nuovo resolver di vista, ma ho provato così tante cose e alla ricerca di una soluzione giusta negli ultimi 2 giorni.
qualsiasi aiuto ?
Grazie
Nessuna soluzione corretta