1

我想在 q=.. 中传递 url .ie 中的“查询”,该怎么做?

String query= request.getParameter("query");
System.out.println(query);
response.sendRedirect("https://www.googleapis.com/customsearch/v1key=AIzaSyDvKmDisCOXJzP7JF24pvXvb2-IwgiDYek&cx=013036536707430787589:_pqjad5hr1a&q=cars&alt=json");
4

2 回答 2

1

1创建一个 HTML 表单

<form action="/googleGateway" method="POST">
  <input type="text" name="query"/>
  <input type="submit"/>
</form>

2创建一个Servlet并将其映射到/googleGateway

来自 doPost()

String query= request.getParameter("query");
//valdate query
System.out.println(query);
response.sendRedirect("https://www.googleapis.com/customsearch/v1key=AIzaSyDvKmDisCOXJzP7JF24pvXvb2-IwgiDYek&cx=013036536707430787589:_pqjad5hr1a&q="+ query +"&alt=json");

也可以看看

于 2012-03-17T06:33:51.350 回答
0

我假设您将在 URL 链接之后附加查询。这样您就无法传递查询,因为查询将包含空格,并且 URL 格式中不允许使用空格。

您可以通过帖子形式的查询。

于 2012-03-17T06:52:34.943 回答