HTML method of the POST method with a request in action URL

Suppose I have a form with = POST method on my page. Now this form has some basic form elements, such as a text box, check box, etc. It has an action url like http://example.com/someAction.do?param=value

I understand that this is actually a controversial thing, but my question is whether it will work in practice.

So my questions are:

  • Since the form method is POST, and I also have a request in my URL (? Param = value) Will it work correctly? that is, I can get the param = value on my receive page (someAction.do)

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

+7
source share
3 answers

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

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

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

If you use EL (JSP expression language), you can also get them as follows:

 ${param.param_name} 

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

In such scenarios, getParameter("param_name) will return the first of them (as described here ), however both of them can be read using the getParameterValues("param_name") method as follows:

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

For more information, read here .

+1
source

Yes. You can get these parameters in your action class. You just have to create a property with the same name (param in your case) where there are receivers and setters.

Code example

 private String param; {... getters and setters ...} 

when you do this, the parameter value (passed through the URL) will be stored in the getters of this particular property. and because of this, you can do whatever you want with this value.

0
source

The POST method simply hides form data from the user. He / she cannot see what data was sent to the server unless a special tool is used.

The GET method allows anyone to see what kind of data they have. You can easily see data from the URL (for example, by seeing key-value pairs in the query string).

In other words, you need to show (possibly non-essential) data to the user using the query string in the form action. For example, in a data table file. To maintain the current pagination state, you can use domain.com/path.do?page=3 as an action . And you can hide other data in the components of the form, for example input , textarea , etc.

Both methods can be detected on the server in the same way. For example, in Java, using request.getParameter("page") .

0
source

All Articles