HTML表单POST方法,其中包含操作URL中的querystring [英] HTML form POST method with querystring in action URL

查看:434
本文介绍了HTML表单POST方法,其中包含操作URL中的querystring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我的页面上有一个带有method = POST的表单. 现在,此表单具有一些基本表单元素,例如文本框,复选框等 它的操作网址为 http://example.com/someAction.do?param=value

Lets say I have a form with method=POST on my page. Now this form has some basic form elements like textbox, checkbox, etc It has action URL as http://example.com/someAction.do?param=value

我确实知道这实际上是一件矛盾的事情,但是我的问题是,它在实践中是否行得通.

I do understand that this is actually a contradictory thing to do, but my question is will it work in practice.

我的问题是

  1. 由于form方法是POST,并且我的URL中也有一个查询字符串(?param = value) 它能正常工作吗?即我可以在接收页面(someAction.do)上获取param = value

  1. Since the form method is POST and I have a querystring as well in my URL (?param=value) Will it work correctly? i.e. will I be able to retrieve param=value on my receiving page (someAction.do)

可以说我使用Java/JSP访问服务器端的值.那么,如何在服务器端获取值呢?语法是否与param = value的访问值以及文本框/单选按钮/复选框等表单元素的语法相同?

Lets say I use Java/JSP to access the values on server side. So what is the way to get the values on server side ? Is the syntax same to access value of param=value as well as for the form elements like textbox/radio button/checkbox, etc ?

推荐答案

1)是的,您将可以访问POST和GET变量,因为您的请求将同时包含这两个变量.因此,您可以相应地使用$ _GET ["param_name"]和$ _POST ["param_name"].

1) YES, you will have access to POST and GET variables since your request will contain both. So you can use $_GET["param_name"] and $_POST["param_name"] accordingly.

2)使用JSP,您可以同时使用以下代码:

2) Using JSP you can use the following code for both:

<%= request.getParameter("param_name") %>

如果您正在使用EL(JSP表达式语言),则还可以通过以下方式获得它们:

If you're using EL (JSP Expression Language), you can also get them in the following way:

${param.param_name}

EDIT :如果请求QueryString和POST数据中都包含param_name,则它们都将作为值数组返回,第一个是QueryString.

EDIT: if the param_name is present in both the request QueryString and POST data, both of them will be returned as an array of values, the first one being the QueryString.

在这种情况下,getParameter("param_name)将返回它们中的第一个(如方法以以下方式读取它们两者:

In such scenarios, getParameter("param_name) would return the first one of them (as explained here), however both of them can be read using the getParameterValues("param_name") method in the following way:

String[] values = request.getParameterValues("param_name"); 

有关更多信息,请 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆