Get JSON Datas using AJAX - Java Servlet


Hi,i am gonna show how servlet implements with JQuery AJax and JSON data for the get method with example.

Example


1.Create a Web Application(New Project->Web Application) in NetBeans, and don't forget to also create the web.xml.

2.Create a Servlet called LoginData
import com.google.gson.Gson;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginData extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                String user=request.getParameter("username");
  String pass=request.getParameter("password");
  Map Admin = new LinkedHashMap();
  Admin.put("1", "Admin1");
  Admin.put("2", "Admin2");
  Admin.put("3", "Admin3");
  
  String json_data=null;
  if(user.equals("sathish")&&pass.equals("sathish"))
  {
   json_data = new Gson().toJson(Admin);
  }
  response.setContentType("application/json");
  response.getWriter().write(json_data);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    public String getServletInfo() {
        return "Short description";
    }// 

3.This is the web.xml that created by the NetBeans when you create the project and the java servlet is already created the appropriate request URL for you.
<servlet>
        <servlet-name>LoginData</servlet-name>
        <servlet-class>LoginData</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>LoginData</servlet-name>
        <url-pattern>/LoginData</url-pattern>
</servlet-mapping>

4.This is a simple HTML page to get the information based on the login.
<html>
    <head>
        <title>Login</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
        </script>
        <script>
            $(document).ready(function(){
                $("#submit").click(function(){
                    var datas='username=' + $('#username').val()
                        + '&password=' + $('#password').val();
                    alert(datas);
                    $.ajax({
                        url:"LoginData",
                        type:"get",
                        data:datas,
                        dataType:"JSON",
                        success: function(data) {
                            
                            var rfew = $('#d1');
                            //rfew.find('li').remove();
                            $.each(data, function(key, value) {
                                rfew.append(key+'-'+ value+'<br>');               
                            });
                        }
                    });
                    return false;
                });
            });
        </script>
    </head>
    <body>
        <div id="d1"></div>
        <form id="myform" method="get">
            Login Name <input type="text" name="username" id="username" /><br>
            Password <input type="password" name="password" id="password" /><br>
            <input type="submit" id="submit" value="Login" />
        </form>
    </body>
</html>

Download Complete Source:





0 comments:

Android Unlock Pattern To Launch Apps For You..

Google knows that Android users are super-busy that they'd need a quick access to specific apps right after the screen is unlocked. Maybe that's the reason it's applied to USPTO for a patent that lets you specify and launch the app depending upon the pattern you draw to unlock your phone's screen.

USPTO has already granted the patent to Google and expect it to make it to the upcoming versions of Android in the next few months. We've no clue whether Google will actually include this feature, but we think it'd be nice to have.




The idea is that you define various patterns that launch specific apps. For example, if you use the 'Z' pattern to unlock your phone, you can set it to launch the dialer app. Once set, whenever you draw the Z pattern to unlock - the dialer will be ready to accept your inputs. Similarly if you use the 'U' pattern to unlock your phone, you can set it to launch camera app. The concept is really simple, but would be quite useful. 


Do let us know what you think about this patent. How do you think Apple should respond with a similar feature? Check the details of the patent on the source link below. 

Source: USPTO


0 comments:

THE EVOLUTION OF GMAIL: INFOGRAPHIC BY GOOGLE:

Gmail is just about to enter its 10th year, and has radically changed the way that hundreds of millions of people interact with their email. Would would have thought nine years ago that email would look anything like it does today!



It reveals some amazing information like the fact that Google released it as an invite-only service initially which has now grown to a whopping 425 million users and that is just till June 2012. There are many more such facts in this infographic. 


So lets have a look at it.




0 comments:

Hit Like and Get Pepsi Cans... Cool Idea by Facebook


Pretty cool idea from marketing and communications agency TBWA Belgiumfor its client, Pepsi: a ‘Like Machine’ that doesn’t accept money but gives people a free can of soda in exchange for a Facebook like.


It’s a step up from promo girls handing out free samples at intersections and shopping malls to random passersby, sure, but I’ll readily admit to cringing when I saw the guy enter his Facebook account details on the ‘social’ vending machine’s touch screen.
Would you log in and like a page for a free can of Pepsi?


0 comments:

Build an Animated Header in jQuery...

Why not give a little flair to your header. This tutorial will show you how to animate your header’s background image using jQuery to give your website that little extra something.

What We Are Building
We are going to build a header that animates it’s background. We will also encase the header in shadow for the little extra dramatic effect.



How it’s Going to Work 
The header background image is going to be super tall. Here is the important part, we’re making a header that is 300px tall. The image’s top 300px and bottom 300px have to be the same. This will allow us to scroll our header seamlessly. So dust of your Photoshop skills you’re going to need them. Not to fret, it’s not that difficult. Just copy the top 300px of your image and paste them on the bottom. Then blend what was originally on your background with what you pasted in.
Header Background Instructions
Now that we have our background image, we will also need to create a shadow overlay image. This will basically be a png with a transparent center that gradually turns to black on the edges. With the CSS we are going to lay this on top of our header to give a dramatic effect.
Header Overlay Diagram
After that it’s just a matter of animating the background image with jQuery so it scrolls.

Bring it All Together

That’s all there is to it. Here is the code all together.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Animated Header</title>
<style type="text/css" media="screen">
 
    body{
        background-color: #000;
    }
 
    /* Center the website */
    #wrapper{
        width:920px;
        margin:0 auto;
    }
 
    /* Give the header a height and a background image */
    #header{
        height:300px;
        background: #000 url(background.jpg) repeat-y scroll left top;
        text-align:center;
    }
 
    /* Create a Shadow Overlay */
    #header div{
        width:920px;
        height:300px;
        background: transparent url(overlay.png) no-repeat scroll left top;
    }
 
    /* Vertically position header text and style it*/
    #header h1{
        padding-top:125px;
        font-family: Arial, "MS Trebuchet", sans-serif;
        color:white;
    }
 
    /* Give basic styles to the body and the navigation */
    #body{
        background-color:#efefef;
        height:500px;
    }
    #nav{
        height:35px;
        background-color: #111;
    }
 
</style>

<!--[if lte IE 6]>
    <style type="text/css" media="screen">
        #header div{
            background-image: none;
            filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='overlay.png', sizingMethod='scale');
        }
    </style>
<![endif]-->

</head>

<body>
 
<div id="wrapper">
    <div id="header">
     
        <!-- Div is for Shadow Overlay-->
        <div>
            <h1>Animated Header Background</h1>
        </div>
    </div>
    <div id="nav">
        <!-- Navigation Goes HERE -->
    </div>
    <div id="body">
        <!-- Body Content Goes HERE -->
    </div>
</div>

</body>  

<!-- Import jQuery-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">

    var scrollSpeed = 70;       // Speed in milliseconds
    var step = 1;               // How many pixels to move per step
    var current = 0;            // The current pixel row
    var imageHeight = 4300;     // Background image height
    var headerHeight = 300;     // How tall the header is.
 
    //The pixel row where to start a new loop
    var restartPosition = -(imageHeight - headerHeight);
 
    function scrollBg(){
     
        //Go to next pixel row.
        current -= step;
     
        //If at the end of the image, then go to the top.
        if (current == restartPosition){
            current = 0;
        }
     
        //Set the CSS of the header.
        $('#header').css("background-position","0 "+current+"px");
     
     
    }
 
    //Calls the scrolling function repeatedly
    var init = setInterval("scrollBg()", scrollSpeed);
 
</script>

</html>


Download Sample Attachment Below:


Thanks & Have Fun :)


0 comments:

JQuery : Flashlight Effect using JQ...Try This...

Flashlight Effect using JQuery : 

Your mouse works as a flashlight and you can read the content only where you are moving your mouse.

The Image

Flashlight

The CSS

body { background:#00022a url(flashlight.jpg) 50% 50% no-repeat; }

The JavaScript

window.addEvent('domready',function() {
 $(document.body).addEvent('mousemove',function(e) {
  this.setStyle('background-position',[e.page.x - 250,e.page.y - 250]);
 });
});

The Output

Download Sample Attachment Below:



Thanks & Have Fun :)


0 comments:

Sending Money through Email (Gmail) is possible NOW..

It’s not easy to send money digitally.

Paypal, an early leader in the field, requires users to have a Paypal account. Users of Venmo, a mobile app, must also have an account, plus download the app.

And Google Wallet, first announced two years ago, has struggled to get wireless carriers and phone manufacturers to install what is called near-field communication technology. NFC technology is what would make it possible for certain Android users to wave their phone at a retailer’s receiver to make a payment.



But now, Google GOOG -1.53% has announced that it will allow Gmail users to attach money to emails, just as they would a photo or a document, as shown in the video. The move could radically transform the way we exchange money with friends, family and even businesses.



Users who link their bank accounts to Google Wallet receive transactions for free. Those using debit or credit cards pay a 2.9% transaction fee, and transactions are limited to $10,000.

Given that Google is the world’s largest email provider, this could help give mobile payments the push they’ve needed to go from being a novelty item to part of our everyday lives.As Quartz points out, text messaging has enabled mobile payments to become widely adopted in the developing world.


Google said it will gradually roll this service out to its Gmail users.


0 comments:

Temple Run Android Game For PC Free Download Without Bluestacks..

Temple Run - the only game in android which has never made any guy bored a bit. The same game is now also gonna hit your PC. But without Blue Stacks. Yeah! that's true. Without Blue Stacks. Because Slue Stacks does work in all PCs we have made this post. 


This post will give Temple Run for PC without Blue Stacks for Free. Just download the game and play.

>>Click here to Download the Game<<

Temple Run Game For PC Is Made By TempleRunForPC. Thanks To Them

Update:

If above download link is not working try below link!!
>>Click Here to Download<<



39 comments:

Using JQuery with Content Master Pages in Asp.net?

jQuery has gained popularity as the de facto standard for JavaScript development and many ASP.NET developers have adopted jQuery as part of their development kits. One question that I am asked frequently is how to use jQuery with an ASP.NET Master Page. Where should the jQuery file and code be placed in a Master Page?

Let’s get started.



Step 1: Create a Master Page (MasterPage.master) and add a reference to the jQuery Library. Now create a folder called ‘Scripts’ and download the latest jQuery library into this folder. Now add references to any CSS files, if any. Create a separate folder to store all CSS and images files. You should always make it a habit to keep your resources in separate folders for better maintainability. The code should look similar to the following:

Step 2: Now create a Content Page called ‘Default.aspx’ and add two TextBox controls to this page as shown below:

Step 3: Now in the ‘Scripts’ folder, create a textboxclone.js file and add the following code in it.

Using the code shown above, as the user types in the first TextBox, we retrieve the value of the first TextBox and set it to the value of the second TextBox. Note: Since we are capturing the keyup event, whenever the user pastes text in the first textbox using Ctrl+v, the contents are cloned into the second textbox, This is however not true when the user right clicks the textbox and chooses paste from the context menu
The last step is to reference this JavaScript file (textboxclone.js) in your Content Page as shown below:
You must be wondering why did we add a link to the textboxclone.js from a Content page rather than doing it from a Master Page. The reason is, if we had referenced the textboxclone.js file in the MasterPage directly, the code would be downloaded for every content page, even if it was not needed. Referencing it from a Content Page makes sure that the resource is used only when this content page is requested. That’s it. Run the code and you will see the textbox text cloning in action.

I hope you liked this article and I thank you for viewing it.

The entire source code of this article can be downloaded over here.


0 comments:

How To Play Subway Surfers On Pc No Surveys, No Bluestacks ,No App Center,Normal Setup!!!!

I am requesting you to follow each and every step so that you will be able to play Subway Surfers on PC or Windows Computer. Its very much simple tutorial which you have to follow after free downloading Subway Surfers for PC.






The method which I am going to show below allows you to free download Subway Surfers for PC and you don’t have to install any kind of emulator as its direct application. You just download it run into your computer system and enjoy playing Subway Surfers on Computer easily.
  1. 1.Free Download Subway Surfers for PC (its .exe file)
  2. 2.Install in to the computer by double clicking on the file.
  3. 3.It will be installed into the system and you will get the game’s icon on desktop
  4. 4.Click on that icon and start playing Subway Surfers on PC for free
  5. 5.This is simple method, isn’t it?
We Already checked that Subway Surfers for PC application and its completely legit and fine to us on your Windows 7/XP operating system.

It was the simple guide with free download links for Subway Surfers PC software and if you have any type of issue then please do comment and let us know. I hope you liked this post on free downloading Subway Surfers for PC. Please do comment and let us know about your views about it!


2 comments: