Saturday, September 13, 2014
Wednesday, August 27, 2014
Web Applications, Java Servlets: A Conceptual Introduction
I am happy to launch a unique kind of conceptual video course on web applications: “Web Applications, Java Servlets: A Conceptual Introduction.” Check it out -- whether you are new to web development or not, and whether you are a hardcore programmer or not, you will love it!
For limited time, I am now offering free lifetime access to it! Follow this link to grab it: https://www.udemy.com/web-application-and-java-servlet-concepts/?couponCode=ALVAX
Feel free to share it with your friends and colleagues, it might be helpful to them!
For limited time, I am now offering free lifetime access to it! Follow this link to grab it: https://www.udemy.com/web-application-and-java-servlet-concepts/?couponCode=ALVAX
Feel free to share it with your friends and colleagues, it might be helpful to them!
Tuesday, August 12, 2014
Up And Running With Spring Framework 4 In Five Hours
Independence day offer valid till August 15 only: Get 80% off ($19 only!) on my "Up And Running With Spring Framework 4 In Five Hours" video tutorial.
Your friends might appreciate you sharing this post with them!
Your friends might appreciate you sharing this post with them!
Sunday, July 27, 2014
Video on basic concepts of web applications, how they work and the HTTP protocol
Here is the first of a series of conceptual videos I have planned to make on web application development using Java Servlets. When the course gets ready, I shall be announcing it here at my blog with some free and heavily discounted coupons. So, if you like this video, please subscribe to my blog to see more free videos by me and know when the course comes out.
Would be glad to hear any feedback. And, if you liked the video, your friends might appreciate you sharing it with them!
Sunday, July 06, 2014
Up And Running With Spring Framework 4 In Five Hours
[Moved from my previous blog]
I recently released a video tutorial on the awesome Spring Framework 4 and its new projects like Spring Boot. Whether you are new to Spring or are already a spring 3 developer, you would like it if you intend to learn Spring 4.
It is priced at $98, but you can get it now at $29 by clicking here. Check it out!
I recently released a video tutorial on the awesome Spring Framework 4 and its new projects like Spring Boot. Whether you are new to Spring or are already a spring 3 developer, you would like it if you intend to learn Spring 4.
It is priced at $98, but you can get it now at $29 by clicking here. Check it out!
Saturday, July 05, 2014
Spring Controllers as JSON API
[This is a post dated June 9, 2013 from my old wordpress blog]
I am currently working on a couple of projects which are single page web applications, where the clients interacts with spring controllers using JSON. Also, in one project we have a wordpress plugin which interacts with our controllers from wordpress sites.
Thought to summarize what all I needed to get this working.
First, let’s look at an example controller method:
The object returned by the method is converted to JSON by Jackson object mapper. For this to work, you have to have an ObjectMapper in your application context. To have it, first include it in your project. That means having this in your pom file, assuming you are using maven:
Then, create an object in your application context. If you are using Java configuration, this should do:
Instead of simlple form fields, request-params or path-variables, sometimes you might need to receive complex JSON data from the client. For that, the client code would look like:
and the controller code like this:
You have to define a SomeClass with fields corresponding to the structure of the data being received.
Finally, if you are switching between http and https protocols, or using your JSON API from a different place, as we do from our wordpress plugin, you will have to circumvent the Javascript Same Origin Policy. For that, I use CORS, or the cors-filter to be specific. To use that, include the following in your pom:
And, have this in your web.xml:
At the client side, my ajax setup, called before any ajax call is made, looks like this:
Please let me know your comments! Hope this would be useful as a quick reference to some (including me) in future.
I am currently working on a couple of projects which are single page web applications, where the clients interacts with spring controllers using JSON. Also, in one project we have a wordpress plugin which interacts with our controllers from wordpress sites.
Thought to summarize what all I needed to get this working.
First, let’s look at an example controller method:
The object returned by the method is converted to JSON by Jackson object mapper. For this to work, you have to have an ObjectMapper in your application context. To have it, first include it in your project. That means having this in your pom file, assuming you are using maven:
Then, create an object in your application context. If you are using Java configuration, this should do:
Instead of simlple form fields, request-params or path-variables, sometimes you might need to receive complex JSON data from the client. For that, the client code would look like:
and the controller code like this:
You have to define a SomeClass with fields corresponding to the structure of the data being received.
Finally, if you are switching between http and https protocols, or using your JSON API from a different place, as we do from our wordpress plugin, you will have to circumvent the Javascript Same Origin Policy. For that, I use CORS, or the cors-filter to be specific. To use that, include the following in your pom:
And, have this in your web.xml:
At the client side, my ajax setup, called before any ajax call is made, looks like this:
Please let me know your comments! Hope this would be useful as a quick reference to some (including me) in future.
Subscribe to:
Posts (Atom)