我是 Ajax 编程的新手,我正在使用 Jquery ajax 将数据提取到服务器并显示为表格格式。在该位置必须显示单选按钮类型。如何调用servlet特定方法如何返回数据。我已经准备好使用json了。任何人都可以帮助我如何调用方法如何返回数据。和建议需要解决问题
提前致谢。
$('#ajaxbutton').on('click',function(){
$.ajax({
type:"post",
url:"Db2",
data:{"labid",100},
sucess:function(){
alert("sucess");
}
});
});
在小服务程序中
public class Db2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws MalformedURLException, IOException {
doProcess(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws MalformedURLException, IOException {
doProcess(request, response);
}
public void doProcess(HttpServletRequest request,
HttpServletResponse response) throws MalformedURLException,
IOException {
Connection con;
PreparedStatement ps, ps1;
PrintWriter out = response.getWriter();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:oracle1", "system",
"sarath");
ps = con.prepareStatement("select trackid,location,to_char(mydate,'dd-mon-yyyy') from information where labid=100");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String location = rs.getString(2);
String track = rs.getString(1);
String myDate = rs.getString(3);
}
} catch (Exception e) {
out.println(e);
}
}
}// end of ServletB