gpt4 book ai didi

java - 如何在 Spring MVC/WebFlow 项目中进行 AJAX 调用

转载 作者:搜寻专家 更新时间:2023-11-01 03:53:26 25 4
gpt4 key购买 nike

我想从 SWF 流中的 View 对 Spring MVC Controller 进行 AJAX 调用。我需要在 portlet 容器内而不是在 portlet session 之外的 servlet 中执行此操作。

我试过使用 <portlet:resourceURL id="myAjax"/>并使用 @ResourceMapping在 Spring Controller 类中,但这会干扰 SWF FlowHandler,因为它试图处理请求。

我想做的事可行吗?如果是这样,有人对如何做有任何建议吗?

谢谢。

最佳答案

在我的 view-state1 spring web flow 中我有这个:

<script type="text/javascript">
function getInfoPersona(tipoSearch) {
dojo.require("dojox.widget.Standby");

if(tipoSearch == 'cedula'){
var param = document.getElementById('cedula').value;
if(!param){
return alert('Escriba una cédula');
}
}else{
var param = document.getElementById('numero').value;
if(!param){
return alert('Escriba un número');
}
}
var url = "/application/personae/info/"+tipoSearch+"/"+param+".json";

var standby = new dojox.widget.Standby({target: "loadingInfo"});
document.body.appendChild(standby.domNode);
standby.startup();
standby.show();
dojo.xhrGet({
// URL del recurso en el servidor
url: url,
handleAs: "json",
timeout: 5000, // Time in milliseconds

// The LOAD function will be called on a successful response.
load: function(response, ioArgs) { //
if(response.nombre){
document.getElementById('infoPersona').innerHTML = '<ul>'+
//'<li>Estatus: '+response.estatus+'</li>'+
'<li>Nombre: '+response.nombre+'</li>'+
'<li>Centro: '+response.centro+'</li></ul>';

if(tipoSearch == "cedula"){
if( response.numero > 0){
document.getElementById("numero").value = response.numero;
//document.getElementById("numero").readOnly = true;
document.getElementById("buttonSearchNumero").disabled = true;
}else{
//document.getElementById("numero").value = '';
document.getElementById("numero").readOnly = false;
document.getElementById("buttonSearchNumero").disabled = true;
}
}

if(tipoSearch == "numero"){
document.getElementById("cedula").value = response.cedula;
document.getElementById("cedula").readOnly = true;
document.getElementById("buttonSearchCedula").disabled = true;
}

if(response.ambito != ''){
document.getElementById('ambito').value = response.ambito;
}


document.getElementById('twitter').value = response.twitter;

document.getElementById('correo').value = response.email;

document.getElementById('numeroTelefono').value = response.telefono;

if(response.parroquiaId > 0){
seleccionarMunicipioParroquia(response.parroquiaId, response.municipioId);
}


document.getElementById('infoPersona').style.visibility = 'visible';
document.getElementById('success').disabled = false;
}else{
if(tipoSearch == 'cedula'){
document.getElementById('infoPersona').innerHTML = 'No se encontraron datos';
document.getElementById('success').disabled = true;
}else{
document.getElementById('infoPersona').innerHTML = 'No se encontraron datos para el número de escrito';
}
document.getElementById("buttonSearchCedula").disabled = false;
document.getElementById("buttonSearchNumero").disabled = false;
}
standby.hide();
document.getElementById('infoPersona').style.visibility = 'visible';

},

// The ERROR function will be called in an error case.
error: function(response, ioArgs) { //
console.error("HTTP STATUS CODE: ", ioArgs.xhr.status); //
dojo.byId("infoPersona").innerHTML = 'No se pudo cargar la información básica de la persona'; //
standby.hide();
document.getElementById('infoPersona').style.visibility = 'visible';
return response; //
}
});
}
</script>

和我的 Controller :

@RequestMapping(value = "/info/cedula/{cedula}.json", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public InfoPersona getPersonaAsJson(@PathVariable("cedula") Integer cedula) {

InfoPersona te = new InfoPersona();
Persona v = Persona.findPersonaByCedulaEquals(cedula);

if(v == null){
return te;
}


setDataPersona(v.getPersonaId(), te);

te.setTipoBusqueda("cedula");

if(!telefonosString.equals("")){
//eliminar la coma final
telefonosString = telefonosString.substring(0, telefonosString.length() - 1);
te.setAllTelefonos(telefonosString);
}

te.setTelefonos(numeros);

return te;
}

关于java - 如何在 Spring MVC/WebFlow 项目中进行 AJAX 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com