Establecer lista desplegable dinámica de hibernación de struts en la página JSP
importar com.ssh2.db.entity.UsersCity
importar com.ssh2.db.entity.UsersCountry
p>
p>
importar com.ssh2.db.entity.UsersProvince
importar com.ssh2.db.entity.UsersProvince
importar com.ssh2; .db.service. acción;
importar javax.servlet.ssh2.db.service.AddressService;
@ SuppressWarnings("serial")
clase pública SelectAjax extiende ActionSupport {
public AddressService addressService; //esta es la capa de servicio Reemplácela con su propio código
public AddressService getAddressService() {
return. direcciónService;
p>
}
public void setAddressService( AddressService direcciónService) {
this.addressService = direcciónService;
}
ejecutar cadena pública() arroja una excepción {
System.out.println("AAAAAAAAAAAAAAAAAA");
Solicitud HttpServletRequest = ServletActionContext.setCharacterEncoding("UTF -8");
Cadena qqq = request.getParameter("changeValue");
Cadena numString = request.getParameter("changeNum");
int num = 5;
Valor de cadena = "";
if(qqq! = nulo &!qqq.equals("")){
String myvalue = new String(qqq.getBytes("ISO-8859-1"), "UTF-8");
valor = mivalor;
System.out.println("Mi " mivalor " ----- " valor);
}
if (numString != null amp;amp; !numString.equals("")){
num = Intege
r.valueOf(numString);
}
System.out.println("num: " num);
Resultado de JSONObject = nuevo JSONObject();
JSONArray array = new JSONArray();
Listlt; UsersCountrygt; list = AddressService.loadAllCountry() // Reemplace con su propio servicio aquí también
String strP = "";
String strC = "";
if(list!=size(); i) {
JSONObject obj = nuevo JSONObject ();
strP = list.get(0).getCountryName();
UsersCountry usuario = list.get(i
System.out); .println("país" usuario.getCountryName());
obj.put("país", usuario.getCountryName());
array.add(i, obj)
}
}
resultado.put("lista", matriz
respuesta.getWriter() .write(); result.toString());
System.out.println("ajax va~~~~");
return null;
}
}
código jsp:
lt; @ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"gt;
lt;! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transicional//EN" "http://www.w3.org/TR/html4/loose.dtd"gt;
lt;htmlgt;
lt;headgt;
lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"gt;
lt;titlegt;Insertar título aquílt;/titlegt;
lt;script type="text/javascript" src="js/jquery-1.4.2.min.js"gt;lt;/ scriptgt;
lt;script type="text/javascript"gt;
$(document).ready(function(){
$.ajax( {
tipo: "obtener",
tipo de datos: "json",
url: "lt;=request.get
ContextPath()gt;/ajax/select", //ruta reemplazada por la tuya propia
//contentType: "utf-8",
éxito: function(resultado){
intentar{
$("#aaa").empty();
$("result.list).each(function(i,item) {
$("#aaa").append("lt;option value=" item.country "gt; " item.country "lt;/optiongt;");
});
}catch(e){
alerta(e);
retorno
}
},
error: function(e){alert('falló 1' " " e);}
});
lt; /scriptgt;
lt; /headgt;
lt; bodygt;
lt; div estilo="ancho: 550px; margen: 20px auto;" ;
lt;divgt;lt;pgt;lt;spangt;lt;/spangt;lt;/pgt;lt;/divgt;
lt;div style="text- align:
lt;form action="" método="post"gt;
lt;div id="myid"gt;lt;/divgt;
lt;div style="float:left" id="abc"gt;
lt;select name="country" id="aaa" style="widht:
lt;opción valor="China"gt;Chinalt;/optiongt;
lt;/selectgt;
lt;/divgt;
lt ;/ formgt;
lt;/divgt;
lt;/divgt;
lt;/divgt;
lt;/ bodygt; <
lt;/htmlgt;
En cuanto al resorte, no es necesario proporcionar la configuración de los puntales.