我正在尝试从servlet获取值到JSP页面,但我无法做到。 servlet页面
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String region = request.getParameter("region");
String secretKey = request.getParameter("secret_key");
String accessKey = request.getParameter("access_key");
String VPC = request.getParameter("vpc");
LOG.info("region is "+region);
if(VPC == null){
List<String> vpcs = RunEc2Command.getVPCForUSer(accessKey, secretKey, region);
if(vpcs != null && vpcs.size() > 0) {
LOG.info("Number of VPCs: "+vpcs.size());
response.setContentType("application/json");
PrintWriter out = response.getWriter();
JSONArray jsonAraay = new JSONArray(vpcs);
LOG.info(jsonAraay);
out.print(jsonAraay);
out.flush();
}
}
}
并在index.jsp页面中,我试图获取JSONArray值
function getSubnets(){
var p = document.getElementById("vpc");
var output2 = $.ajax({
type: 'POST',
url: 'http://localhost:8066/VMMigratorNew/ec2util',
data: {
"vpc":p.value
},
dataType:'json',
success: function(data) {
$.each(data.jsaonArray, function(index){
var selectBox = "<select>"
$.each(data.jsonArray[index], function(key , value){
selectBox+="<option>"+key + "& value" + value + "</option>";
});
selectbox+="</select>";
$('vpc').html(selectBox);
});
//return output2.responseText;
}
});
} 下拉框未填充,下拉框的代码为
<select id="vpc" name="vpc" class="form-control" placeholder="Choose VPC" >
<option value="" default selected>Select VPC</option>
</select>
我是JSON的新手,感谢您的帮助。
答案 0 :(得分:0)
试试这个......
Panel1.BackColor = Color.FromArgb(icolor Or &HFF000000)