Reputation: 157
How can I allow my servlet to accept 4 parameters via HTTP POST through a URL?
Example of URL: http:///servlet
The information returned will be in text format using the JSON format.
JSONObject myStr = new JSONObject();
Am using Model-View-Controller access model. JSP are my view pages, Servlets are my controllers and model are my data managers.
Thanks.
Upvotes: 0
Views: 2186
Reputation: 1108692
How can I allow my servlet to accept 4 parameters via HTTP POST through a URL?
Just invoke a HTTP POST request with those 4 parameters.
Either by a simple HTML form.
<form action="servletURL" method="post">
<input type="hidden" name="param1" value="value1">
<input type="hidden" name="param2" value="value2">
<input type="hidden" name="param3" value="value3">
<input type="hidden" name="param4" value="value4">
<input type="submit">
</form>
Or by Ajax (with little help of jQuery).
<script>
var params = {
param1: 'value1',
param2: 'value2',
param3: 'value3',
param4: 'value4'
};
$.post('servletURL', params, function(response) {
alert(response);
});
</script>
Then they'll be available the usual request.getParameter(name)
way in servlet's doPost()
method.
Upvotes: 2