接口是第三方提供的,目前已經(jīng)調(diào)通,查詢時需要 傳遞參數(shù) 與調(diào)用相關(guān)方法。請問在 在調(diào)用接口時,如何傳值與獲得參數(shù)。
jsp 頁面用
function x(){
var name=$("#name").val(); //查詢時的參數(shù)
$.ajax({
type: 'post',
url: "/servlet/ls",
timeout: 300,
dataType:"JSON",
async:false,
success: function (success) {
}
});
}
Java 中該如何設(shè)置參數(shù), public void doGet(HttpServletRequest request, HttpServletResponse response,String name)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String ls = Service.findls("{\"name\":"+name+"}");
System.out.println(ls);
out.write(ls);
out.flush();
out.close();
}
2 回答

慕慕森
TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊
function x(){ var name=$("#name").val(); //查詢時的參數(shù) $.ajax({ type: 'post', url: "/servlet/ls", timeout: 300, dataType:"JSON", data:"參數(shù)1=值1&參數(shù)2=值2", async:false, success: function (success) { } }); }
String parm1 = request.getparameter("參數(shù)1"); String parm2 = request.getparameter("參數(shù)2");

largeQ
TA貢獻(xiàn)2039條經(jīng)驗 獲得超8個贊
function x(){
var name=$("#name").val(); //查詢時的參數(shù)
$.ajax({
type: 'post',
url: "/servlet/ls",
timeout: 300,
dataType:"JSON",
data:{“name1”:name,“name2”:name2 ...},// 格式編寫java中的map一樣
async:false,
success: function (success) {
} });
}
String parm1 = request.getparameter("name1");
String parm1 = request.getparameter("name2");
另外樓主可以把a(bǔ)jax封裝下,流傳參接口即可(同/異步,url,傳參....),方便下次使用
添加回答
舉報
0/150
提交
取消