响应json数据之发送ajax的请求
2021-05-07 23:28
标签:where cti null ror new ted stack sonar pos 一、前端异步请求代码: 二、WEB-INF下的web.xml的servlet-url的配置方法: 三、后端的Java代码: 响应json数据之发送ajax的请求 标签:where cti null ror new ted stack sonar pos 原文地址:https://www.cnblogs.com/almm/p/12082954.html$.ajax
({
type: "POST", //请求的方式
url: "outputservlet3", //请求url
data: {}, //前端向后端传送的数据
dataType: "json", //数据格式json
error: function () //请求错误的回调函数
{
},
success: function () //请求成功的回调函数
{
}
})
//响应的是post请求"font-size:14px;">protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//doGet(request, response);
OracleConnection myoracle=new OracleConnection ();
Connection conn=null;
PreparedStatement pre=null;
ResultSet result = null;
String sql="select RANK, POINT from MAPGIS.FIRERANK,MAPGIS.WUHAN where FIRERANK.WUHAN_ID=WUHAN.ID ";
JSONObject jsonObject = new JSONObject();
PrintWriter out = response.getWriter();
try
{
conn = myoracle.getConnection1();
pre = conn.prepareStatement(sql);
result = pre.executeQuery();
while(result.next())
{
out o1=new out();
o1.setRank(result.getInt("rank"));
JGeometry geom = JGeometry.load(result.getBytes(2));
point= geom.getLabelPointXYZ();
o1.setX(point[0]);
o1.setY(point[1]);
out1.add(o1);
}
JSONArray ja3=JSONArray.fromObject(out1);
jsonObject.put("point", ja3);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
myoracle.close(result, pre, conn);
}
out.print(jsonObject.toString());
}
运行成功
上一篇:压力测试 Apache ab
下一篇:css的filter属性
文章标题:响应json数据之发送ajax的请求
文章链接:http://soscw.com/index.php/essay/83875.html