lundi 24 août 2020

Using JSON returned from jersey method

I am currently working with Jersey to support RESTful web service with jsp.

I have a form submitted from client side from jsp that calls upon REST api.

index.jsp

<form action = "../project/rest/user/transfer" method = "POST">
            <div class="row">
                <div class="col">
                    <h3>Sender Address</h3>
                    <input type = "text" name = "sender_address" id="sender_address">
                </div>
                <div class="col">
                    <h3>Receiver Address</h3>               
                    <input type = "text" name = "receiver_address" id="receiver_address">
                </div>
                <div class="col">
                    <h3>Amount</h3>
                    <input type = "number" name = "amount" id="transferAmount" />
                </div>
            </div>
            <br>
         <input id="submitButton" type = "submit" value = "Transfer"/>
      </form>

java class that uses jersey

@POST
@Path("/transfer")
@Produces(MediaType.APPLICATION_JSON)
public ResponseMessage transfer(@FormParam("sender_address") String from, @FormParam("receiver_address") String to, @FormParam("amount") int value){
    
    ResponseMessage msg = new ResponseMessage();
    msg.setResponseCode("200");
    msg.setResponseMessage("some message");
    Transaction trans = new Transaction();
    msg.setData(trans);
    
    return msg;     
}

When the form is submitted, this calls upon the above java method and display a new page that displays the java method info in JSON format.

However, I would like the page to stay on the same page but be able to retrieve/use the Transaction data returned from that java method(JSON object).

Is there a way to perform something of similar?

Thanks




Aucun commentaire:

Enregistrer un commentaire