我有一个Servlet,它向我旋转了一些值http://localhost:666/sg/queue?q=21343434
我想获得值q
@WebServlet("/queue")
public class QueueServlet extends HttpServlet {
private List<String> queue;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
queue = new ArrayList<String>();
queue.add("12324543254235");
out.print(queue.size());
out.print(request.getAttribute("q").toString());
}
}
但是当我写out.print(request.getAttribute("q").toString());
时,没有显示任何内容
当我写out.print(request.getQueryString());
时显示q=21343434
但我只需要获得非常值q
答案 0 :(得分:1)
使用request.getParameter()获取url的param,getAttribute()用于获取已发布请求的数据。