How do I make a HTML GET form with an action url that does not include ?<id>= in it?

HashTables :

I use the Java spark web framework and using it for REST API's.

The GET structure is /foo/bar not /foo?name=bar. However with using HTML the form always submits like the later example and so Java Spark can not understand it.

Java Spark GET method Example:

 get("/hello/:name", (request, response) -> {
                    return "Hello: " + request.params(":name");
            });

HTML GET form :

<form method="GET" action="/hello">
    <input type="text" name="name" id="name">
    <input type="submit" value="Submit">
</form>
RealHowTo :

With a simple javascript function, you can build the action url.

<script>
function submitFunction() {
   document.form1.action= "/hello/" + document.form1.name.value;
   // alert(document.form1.action);
   document.form1.submit();
   }
</script>

<form method="GET" name="form1">
    <input type="text" name="name" id="name">
    <input type="button" value="Submit" onClick="submitFunction()">
</form>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=19023&siteId=1