简体   繁体   English

request.getParameter on

[英]request.getParameter on <a>

I current have some instances of input buttons and use request.getParameter to the request when the button is clicked.我目前有一些输入按钮的实例,并在单击按钮时将 request.getParameter 用于请求。 Like this:像这样:

<input type ="submit" name="test" value="test"/>

String t = request.getParameter("test");
    if (t != null) {
        System.out.print("k");
    }

I was wondering if there is a similar method for submitting data from a link , but I have not seen to come across any.我想知道是否有类似的方法可以从链接提交数据,但我没有遇到过。 In other words, I want to use a link instead for for the same result.换句话说,我想使用链接来代替相同的结果。

The application use servlets and the method="get" to handle the submit.应用程序使用 servlet 和 method="get" 来处理提交。

If you want to send the parameters through GET, then you should send them as query parameters, like: ?key1=value1&key2=value2 .如果您想通过 GET 发送参数,那么您应该将它们作为查询参数发送,例如: ?key1=value1&key2=value2

For your use case, it should work if you replace the input type with the anchor element:对于您的用例,如果您用锚元素替换输入类型,它应该可以工作:

<a href="/your-path?test=value">link</a>

As a side note, just make sure that you understand the difference between GET and POST.作为旁注,只需确保您了解 GET 和 POST 之间的区别。 Some notes here , or simply Google it.这里有一些注释,或者干脆谷歌一下。 What you've tried, with the input submit element should be handled via POST, it's really strange that it even worked in the first place.你已经尝试过,输入提交元素应该通过 POST 处理,它甚至首先工作真的很奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM