lundi 13 juin 2016

How to design a web form using MVC pattern

I am new to Restful web services in Java and trying to discover it by using MVC design pattern.

I have a simple HTML form with one button and one input text box. When the user types something into the text box, I want to store this data in DB.

This is part of my HTML code:

When the button is clicked, I call "doneButton()" function as

function doneButton() { var param = document.getElementById("text").value; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { document.getElementById("text").innerHTML = xhttp.responseText; } }; xhttp.open("GET","MYURL"+param); xhttp.send(); }

I am able to call my RestFul web service by the AJAX code above.

In my web service, I call my model class and establish DB connection there. After that, I call my DAO class from my model class and store the required data in DB table.

As far as I know MVC design pattern:

I should not call a web service directly from view. I should first call

  • A controller from the view
  • This controller should call the Restful web service.
  • The web service should call the model class.
  • The model class should class DAO and DB operation.

Is this corrent in terms of MVC design pattern?

Can I call a Restful Web service directly from view in MVC design pattern?

I use jersey in web.xml:

RESTful Service com.sun.jersey.spi.container.servlet.ServletContainer 1 RESTful Service /webservices/*

Can you please help me to understand how I should build my application using MVC design pattern?

Thank you for your help.

Best Regards

Aucun commentaire:

Enregistrer un commentaire