HTML form POST method with querystring in action URL

元气小坏坏 提交于 2019-12-05 04:58:07

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) Using JSP you can use the following code for both:

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

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

${param.param_name}

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.

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"); 

For further info, read here.

Yes. You can retrieve these parameters in your action class. Just you have to make property of same name (param in your case) with there getters and setters.

Sample Code

private String param;

{... getters and setters ...}

when you will do this, the parameters value (passed via URL) will get saved into the getters of that particular property. and through this, you can do whatever you want with that value.

The POST method just hide the submitted form data from the user. He/she can't see what data has been sent to the server, unless a special tool is used.

The GET method allows anybody to see what data it has. You can easily see the data from the URL (ex. By seeing the key-value pairs in the query string).

In other words it is up to you to show the (maybe unimportant) data to the user by using query string in the form action. For example in a data table filter. To keep the current pagination state, you can use domain.com/path.do?page=3 as an action. And you can hide the other data within the form components, like input, textarea, etc.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!