java Jetty Server - 如何处理带参数的 GET 请求?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5790321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jetty Server - how to handle a GET request with parameters?
提问by jellyfish
This must be awfully simple, but I didn't find an answer.
这一定非常简单,但我没有找到答案。
Hereis an easy example on how to listen to a get request with a jetty server.
这是一个关于如何使用码头服务器侦听获取请求的简单示例。
However, it doesn't cover the case that it's not just a "http://www.foo.com/bar" request, but something like "http://www.foo.com/bar?name=guy&value=1".
但是,它不包括它不仅仅是“ http://www.foo.com/bar”请求的情况,而是类似于“ http://www.foo.com/bar?name=guy&value=1”。
So how do I get the parameters in jetty?
那么如何获取jetty中的参数呢?
回答by Sebastien Lorber
This is the API for ServletRequest. You should use:
这是 ServletRequest 的 API。你应该使用:
request.getParameter("name");
request.getParameter("value");
回答by kalyan
request.getParameter("name");
request.getParameter("value");
回答by DaveH
You can use request.getParameter("name") and request.getParameter("value") in the doGet method of your servlet.
您可以在 servlet 的 doGet 方法中使用 request.getParameter("name") 和 request.getParameter("value")。