我正在使用 Eclipse 開發一個 Web 服務,為了嘗試它,我啟動了 tomcat 服務器并嘗試使用參數的 http 請求。問題是我給出的參數似乎被忽略了: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); if(session.getAttribute("lat") == null && session.getAttribute("lon") == null) { session.setAttribute("lat", request.getAttribute("lat")); session.setAttribute("lon", request.getAttribute("lon")); response.setContentType("text/plain"); response.getWriter().append("RECEIVED"); } else {使用調試器,我可以看到該對象request不包含我的參數。
1 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
您正在嘗試獲取 HttpSession 屬性,但不是 URL 中傳遞的參數。你需要使用
request.getParameter("lat");
以字符串形式返回請求參數的值,如果參數不存在則返回 null。請求參數是隨請求一起發送的額外信息。對于 HTTP Servlet,參數包含在查詢字符串或發布的表單數據中。
您還可以獲取所有參數Map
Map<String,String[]>?getParameterMap()
返回此請求的參數的 java.util.Map。
請求參數是隨請求一起發送的額外信息。對于 HTTP Servlet,參數包含在查詢字符串或發布的表單數據中。
添加回答
舉報
0/150
提交
取消