Essentially I have a front end using AngularJS and a back end using Java. I need to be able to send a value from the front end via an input box to the back end to make use of in the Java.
I found a basic example, namely:
Java
package com.mkyong.rest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
@Path("/user")
public class UserService {
@POST
@Path("/add")
public Response addUser(@FormParam("name") String name,
@FormParam("age") int age) {
return Response.status(200)
.entity("addUser is called, name : " + name + ", age : " + age)
.build();
}
}
HTML
<html>
<body>
<h1>JAX-RS @FormQuery Testing</h1>
<form action="rest/user/add" method="post" >
<p>Name : <input type="text" name="name" /></p>
<p>Age : <input type="text" name="age" /></p>
<input type="submit" value="Add User" />
</form>
</body>
</html>
I understand the @FormParam parts and how that works but what I don't understand is how the @Path works as well as the @POST. Is this linked to the form action and is it that simple or is there some step in between?
A general explanation of how this works/if my assertions are correct would be appreciated.