I'm new at Spring MVC framework i want to learn how to fully separate frontend(html,js etc.) and backend(java).
I'm going to use RESTfull services, play with JSONs.
I think i'm going to build Single Page Application.
Most of tutorials shown in jsp pages which i dont like.
I saw my friends company project(Using Spring MVC) they used Embedded Jetty server and in server configuration they assigned two different paths for frontend and backend paths.
I saw frontend codes there was only html javascripts etc. on the backend side the approach was the same.(Fully Separated !!!)
My question is:'How they pass requests from frontend to backend and get results from backend and update frontend'.
Also they were using Maven backend and frontend defined as modules in the root.
Could you share tutorials so i can understand playing with codes ?
'How they pass requests from frontend to backend and get results from
backend and update frontend'
They probably use HTTP[S] as the transport and JSON as the data representation format. Browsers support AJAX which allows you to make HTTP connections without reloading the page.
Could you share tutorials so i can understand playing with codes ?
No, that's not what this site is for.
Comments:
JSP is still very useful for generating HTML on the server. This is pretty close to necessary if you want Google to crawl your site.
Check out Spring Data REST for a framework for quick REST APIs.
Also check out ExtJS or Dojo for good Single Page App frameworks.
Related
I am considering moving from server-side rendering view technologies like JSP, Struts to client-side rendering view technologies using AngularJS,
A popular Javascript framework for modern browsers.
When we are making this change and what are all the things that I may encounter.
If anybody who are experienced in Spring Web MVC and JSP development and would know how Spring MVC can work together with a client-side Javascript like AngularJS.
Kindly Answer.
You have to rewrite the view part using angularJS, and replace the logic from the server with a REST API.
It's often a huge work, and the hardest part is to migrate the existing server-side session management to the browser, because a REST API is stateless.
Below is one of the suggested way in which i recently migrated my existing spring MVC web-application in Single page application using AngularJs as client side java-script framework:
1).First you needs to bisect your core business logic which must needs to handle in DB layer,if not done already. i.e. SP's,trigger's,etc...
2).Then for the thing mentioned as hardest by Toilal ("to migrate the existing server-side session management to the browser, because a REST API is stateless"), you can consider Spring Boot as one of the options to build things quickly instead of Spring MVC with fusion of java8 features to yield the JSON response via API's.
3).And than last but not the least, build UI layer with AngularJS in front End encapsulating the data returned by the spring boot API's. Please note that as angular is super power full, you can do most of your business logic at client side,your DB layer just needs to give you the whole bunch of business data to render the screen,other things you can easily handle in angular.
Thus, this way by making the DB layer thin and imbibing angular at front end, you can improve performance of your existing application drastically.
You can also check this AngularJS with Spring-mvc useful thread in same context.
How to display Backend data using AngularJS in Java web Application.
Do I need to use RESTfull Web Services.
If I don't want to use RESTfull web services, then how should I proceed.
(In my java web application m using Spring and Hibernate.)
AngularJS is a framework used to develop single page web applications which doesn't need refreshing and will act like a mobile application.
For this purpose, all the data required by the front end needs to come from some sort of a backend API. REST is widely used for this purpose in many leading high scale websites like twitter/facebook etc.
You should develop your Java Web Application as an API without no/less HTML pages and use that in your AngularJS front end.
RESTfull web services provide and easy way to integrate your AngularJS frond end with database. It is the most popular one. But it is not the only one.
You can also achieve this via different techniques.
All you need is to make call to a server technology that returns a JSON object.
That particular server technology (even a simple JSP/Servlet) can interact with database and return the expected data in JSON format.
This link provides a simple example to help you begin with.
I am planning to start a project and I am looking for the best approach to make a RIA application using AngularJS.
Right know I am pretty sure of those technologies:
AngularJS (+ bootstrap CSS) for the client UI, logic and server
requests.
Spring for bootstrapping the server business logic.
Hibernate + MySQL for persistent data access
Jersey for the Restful web service API.
Spring Security for url and data protection over authentication.
The only piece I feel is not ok is that my application will not be the typical one page app, because it will be large and I want to break it into multiple one page apps, some protected and others public. To serve every index.html I want another technology like Spring MVC, making those small one page apps secure for this points, and also not allowing the access to some resources.
¿Do you think this is a good approach or you would change any of this technologies (like supressing jersey/Spring MVC redundant dependencies)?
i think that in general your aprroach is a good one, but maybe you could use the webapp generator yeoman with the JHispster, a java web app generator.
Or if you don't like the ideia you could add to your data access layer the Spring-Data-JPA, because you will avoid to write the boilerplate code.
I would like to add a Web User Interface for an existing Java project I did time ago. I learned basics of AngularJS on codeschool.com courses and now I know how to send an http or REST request to get data for my web UI.
My Java project has a set of methods that elaborate some data from a local database and return integers or integers arrays.
The goal of the interface would be to show a bunch of charts and data directly from that Java project.
What would be the most appropriate way to do this? I heard of implementing REST services on my Java project but it seems overkill for the purpose and i'm totally confused by all the frameworks for this. What would you use?
Thanks everyone for your answers!
I would use SprinvMVC to provide data from server to client side.
Here is my project from which you can start and learn basics :
https://github.com/xwid/thaimaster
Basicly you should create spring controllers mapped to urls, by doing it this way, you will be able to retrive server data using angular js.
http://www.javabeat.net/spring-mvc-angularjs-integration/
If you don't want to use a full REST framework such as Jersey, another possibility would be to use an embeddable HTTP server (there are several) and handle the requests yourself. This would mean that requests to something like /myapp/ would return your AngularJS filled HTML page, and requests to /resources/* would provide with REST functionality.
This would give you a standalone Java program that doesn't need a servlet container, but it would be a somewhat hacky solution. Not production grade, but you'd probably learn something from having to handle the HTTP traffic yourself.
With the Spring Framework's SprigBoot, it's quite easy to implement a REST service and have a runnable java application. You can follow this Building a RESTful Web Service guide from spring.io. They are clear and quickly understandable.
Also if you are not already familiar, through these guides you can have a glimpse of gradle and maven as well.
I'm trying to choose best set of tools to create Single Page Applications. I would like to be able to use Java and Hibernate on server side along with MySQL. But what about ajax layer of SPA?
Maybe I have entirely wrong idea about that and Java and Hibernate make no sense in this case? But than how to implement complex server side operations?
It's rather question of UI part. The page asks a server for pages data. Java + hibernate could be used to implement service (e.g. REST service which returns data in JSON format). You can use SpringMVC to implement the service.
AJAX calls the service and process obtained data.
You can use angularJS for creating Single Page Application. this is the best framework i found for SPA development so far and using in most of projects developing which needs SPA.
for sample application refer to github
and detail about angularJS