• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why are there two types of methods for a particular operations in a project?

 
Ranch Hand
Posts: 240
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a confusion regarding "Web Services",
Assume there is an 'Employee Management Web application'.
You have to perform a task that is to display all the records of employees from 'Employee' table.
you have written an 'EmployeeController' class where you are returning the "List" of employee objects to the browser through ModelAndView object, you even mentioned the "view" page name as well:



Now here it leaves me confused....the below written RESTful WS method performs the same task what the above method does but it sends the Employees objects in JSON format.
I want to know when does the above method has to execute and when this below one?
How relevant are both to each other?
Does every java based web project contains both types of methods for a particular operations?

I hope you have understood what i want to ask. Your help will be much appreciated. Thanks!
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that this codereturns object list named "employees" for the view named "page".
This view would most likely generate some document (often HTML or PDF) and a listing of objects as created by the view and template engine.

"/show/allEmployees" is the data rendered and ready for immediate presentation (usually via web browser) thanks to the logic provided by the view.

However this code:only returns the data without any extra markup. This data is most likely returned at a listing of JSON or XML objects.

The "allEmployees" call is a REST call which would be consumed by another program, maybe IOS, Android etc. This is only the data and nothing but the data.
Usually the consuming program has to add some extra display elements/design to the data before being displayed.

They are related in that they provide the same information, but in different ways for the consuming client.

Arun Singh Raaj wrote:Does every java based web project contains both types of methods for a particular operations?


No, as there is not always a reason do. Some data should not be consumed via REST for business reasons or other reasons.
Often most only program what they have to and nothing else. So you may see REST data or you may just regular data or you may see both.
Depends on what the project needs to provide to the end users/consumers.
 
Saloon Keeper
Posts: 15731
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends heavily on whether your application's presentation layer is mostly in the client or in the server.

For instance, it's possible to have an application that consists of a lot of static HTML pages, and every time you make a request the server builds a new web page. In this case, your server will mostly have methods of the first kind, that return a ModelAndView.

The other extreme is an application that consists of a single dynamic web page. In this case, the server has one method that returns a ModelAndView containing the entire client-side application, and all interaction with the server is done through AJAX requests that get handled by methods of the second kind, that return a JSON response body.

Most web applications are somewhere in the middle. They host a couple of different HTML pages, which to a varying degree communicate with the server with AJAX request.
 
Arun Singh Raaj
Ranch Hand
Posts: 240
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for clearing that up... Stephan van Hulst, Pete Letkeman.
 
I am mighty! And this is a mighty small ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic