Obtaining values ​​in Java via an advanced interface input bo…

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:


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;

public class UserService {

public Response addUser(@FormParam("name") String name,
        @FormParam("age") int age) {

    return Response.status(200)
            .entity("addUser is called, name : " + name    + ", age : " + age)



JAX-RS @FormQuery Testing

Name :

Age :

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.

What i got from your question you want to more about @POST
and @PATH
if yes. than @POST
is tell you the type of request like post, get, put, delete
etc. that means your addUser method call only when POST request come to server but path should correct. Now @PATH
tells you about the URL to call addUser
method, In your case @Path("/user") public class UserService
means whenever a request come to /user it call you UserService class, further if we have multiple method in same class like adduser, deleteuser, getuser than you need to tell server which method call for URL so we put @PATH on method and our URL is form. Example

public Response addUser
//URL for aboue method is /user/add
public Response deleteUser
//URL for above method is /user/delete

I hope you under stand the URL mapping in webservice, you need more study about URL mapping in web service.

is also depende upon the web.xml configuration.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Obtaining values ​​in Java via an advanced interface input bo…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录