Application development and sharing our knowledge to developer to developer for helping knowledge to build a effective solution for web architect.
Pages
▼
Saturday, October 10, 2015
AngularJS using java example
AngularJS Example Using a Java RESTful Web Service
AngularJS is the current MVV-Whatever JavaScript framework by Google.
Among other things, it provides bidirectional data binding.
Although I’m neither a Java nor a JavaScript expert, I choose the following scenario for my ‘Hello-World’ example:
Java backend provides a RESTful web service.
AngularJS consumes the web service.
That’s it.
Project structure
I intentionally put the backend and frontend code in the same project
to simplify the example. In a real project you probably want to have
seperate projects for front- and backend.
src/main/java is the backend. src/main/webapp/js is the frontend. src/main/webapp/ also includes a copy of angular-seed.
RESTful web service (backend)
Jersey is the Java reference implementation for providing REST.
Install the following dependencies in your pom.xml:
pom.xml
123456789101112131415161718
<!-- .. --><!-- RESTful web service: Jersey --><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-server</artifactId><version>1.17.1</version></dependency><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-servlet</artifactId><version>1.17.1</version></dependency><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-json</artifactId><version>1.17.1</version></dependency><!-- .. -->
Add the following servlet snippet to your web.xml:
No comments:
Post a Comment