Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

October 30, 2017

Adding google map to Java Server Page to show the location of your business

Adding google map with markers in to website

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
        <title>Branch Details</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <link rel="stylesheet" type="text/css" href="../CSS/branchForm.css"/>
        <link href="CSS/jquery-ui.css" rel="stylesheet">
        <script type="text/javascript" src="JS/jquery.ui.datepicker.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>
        <link href="CSS/style.css" rel="stylesheet">
     
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

    </head>
    <body> 
        <form action="" class="register">
        <!--
            <h1>Branch Registration</h1>
            <fieldset class="row1">
                <legend>Account Details
                </legend>
                <p>
                    <label>Category
                    </label>
                    <input type="text"/>
                    <label>Firm Code
                    </label>
                    <input type="text"/>
                </p>
                <p>
                    <label>Name
                    </label>
                    <input type="text"/>
                    <label>Constituency
                    </label>
                    <input type="text"/>
                    <label class="obinfo">* mandatory fields
                    </label>
                </p>
            </fieldset>
             -->
            <fieldset class="row2">
           
                <legend>Branch Details
                </legend>
             
                <p>
                    <label>Name
                    </label>
                    <input type="text"/>
                </p>
             
                <p>
                    <label>Firm Code
                    </label>
                    <input type="text"/>
                </p>
             
                <p>
                    <label>Category
                    </label>
                    <input type="text"/>
                </p>
           
             
                <p>
                    <label>Constituency
                    </label>
                    <input type="text"/>
               
                </p>
             
                <p>
                    <label>Address *
                    </label>
                    <input type="text" class="long"/>
                </p>
                <p>
                    <label>Location *
                    </label>
                    <input type="text" id="pac-Input" placeholder ="Enter your location"  />
                </p>

                <p>
                    <label>City *
                    </label>
                    <input type="text" class="long" id="cityTxt"/>
                </p>
                <!--
                <p>
                    <label>Country *
                    </label>
                    <select>
                        <option>
                        </option>
                        <option value="1">United States
                        </option>
                    </select>
                </p>
                -->
                <p>
                    <label>Inauguration Date *
                    </label>
                    <input type="text" maxlength="10" id="datepicker"/>
                </p>
                 <p>
                    <label>Lat *
                    </label>
                    <input type="text" maxlength="2" id="latBox" />
                    </p>
                    <p>
                    <label>Lon *
                    </label>
                    <input type="text" maxlength="2" id="lngBox" />
                </p>
             
                <p>
                    <label class="optional">Website
                    </label>
                    <input class="long" type="text" value="http://"/>

                </p>
            </fieldset>
            <fieldset class="row3">
                <legend>Branch Location
                </legend>
                <!--
                <p>
                    <label>Gender *</label>
                    <input type="radio" value="radio"/>
                    <label class="gender">Male</label>
                    <input type="radio" value="radio"/>
                    <label class="gender">Female</label>
                </p>
             
                -->
                  <!--
                <p>
                    <label>Inaugration date
                    </label>
                    <select class="date">
                        <option value="1">01
                        </option>
                        <option value="2">02
                        </option>
                        <option value="3">03
                        </option>
                        <option value="4">04
                        </option>
                        <option value="5">05
                        </option>
                        <option value="6">06
                        </option>
                        <option value="7">07
                        </option>
                        <option value="8">08
                        </option>
                        <option value="9">09
                        </option>
                        <option value="10">10
                        </option>
                        <option value="11">11
                        </option>
                        <option value="12">12
                        </option>
                        <option value="13">13
                        </option>
                        <option value="14">14
                        </option>
                        <option value="15">15
                        </option>
                        <option value="16">16
                        </option>
                        <option value="17">17
                        </option>
                        <option value="18">18
                        </option>
                        <option value="19">19
                        </option>
                        <option value="20">20
                        </option>
                        <option value="21">21
                        </option>
                        <option value="22">22
                        </option>
                        <option value="23">23
                        </option>
                        <option value="24">24
                        </option>
                        <option value="25">25
                        </option>
                        <option value="26">26
                        </option>
                        <option value="27">27
                        </option>
                        <option value="28">28
                        </option>
                        <option value="29">29
                        </option>
                        <option value="30">30
                        </option>
                        <option value="31">31
                        </option>
                    </select>
                    <select>
                        <option value="1">January
                        </option>
                        <option value="2">February
                        </option>
                        <option value="3">March
                        </option>
                        <option value="4">April
                        </option>
                        <option value="5">May
                        </option>
                        <option value="6">June
                        </option>
                        <option value="7">July
                        </option>
                        <option value="8">August
                        </option>
                        <option value="9">September
                        </option>
                        <option value="10">October
                        </option>
                        <option value="11">November
                        </option>
                        <option value="12">December
                        </option>
                    </select>
                 
                    <input class="year" type="text" size="4" maxlength="4"/>e.g 1976
                </p>
             
           
                <p>
                    <label>Nationality *
                    </label>
                    <select>
                        <option value="0">
                        </option>
                        <option value="1">United States
                        </option>
                    </select>
                </p>
               
                <p>
                    <label>Children *
                    </label>
                    <input type="checkbox" value="" />
                </p>
             
                <img src="../IMAGES/googleMap.jpg" style="width:398px;height:209px;">
                -->
                <div id="map"></div>
    <script>
      function initMap() {
        var mapDiv = document.getElementById('map');
       
        var map = new google.maps.Map(mapDiv, {
          center: {lat: 11.253069, lng: 75.78281},
          zoom: 12
        });
       
        var marker = new google.maps.Marker({
        position: {lat: 11.253069, lng: 75.78281},
        map: map,
        title: 'Triveni location',
        draggable: true
          });
       
        var locationInput = document.getElementById('pac-Input');
       
        google.maps.event.addListener(marker, 'dragend', function (event) {
        document.getElementById("latBox").value = this.getPosition().lat();
        document.getElementById("lngBox").value = this.getPosition().lng();
        //document.getElementById("cityTxt").value = locationInput;
        });
       
        var autocomplete = new google.maps.places.Autocomplete(locationInput);
        autocomplete.bindTo('bounds', map);
       
        var infowindow = new google.maps.InfoWindow();
       
          autocomplete.addListener('place_changed', function() {
          alert(" autocomplete add listener ");
         
            infowindow.close();
            //marker.setVisible(false);
            var place = autocomplete.getPlace();
            if (!place.geometry) {
              window.alert("Autocomplete's returned place contains no geometry");
              return;
            }
         
        var address = '';
            if (place.address_components) {
              address = [
                (place.address_components[0] && place.address_components[0].short_name || ''),
                (place.address_components[1] && place.address_components[1].short_name || ''),
                (place.address_components[2] && place.address_components[2].short_name || '')
              ].join(' ');
            }

            infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
            infowindow.open(map, marker);
         
        });
       
       
          //});
        /*
        var input = document.getElementById('pacInput');
          var searchBox = new google.maps.places.SearchBox(input);
          map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
         
          searchBox.addListener('places_changed', function() {
            var places = searchBox.getPlaces();

            if (places.length == 0) {
              return;
            }
        */
       
      }
    </script>
   
                <!--
                <div class="infobox"><h4>Helpful Information</h4>
                    <p>Here comes some explaining text, sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
                </div>
                -->
            </fieldset>
            <fieldset class="row4">
                <legend> blah blah blah...
                </legend>
                <p class="agreement">
                    <input type="checkbox" value=""/>
                    <label>*  Is the <a href="#">unit currently working</a></label>
                </p>
                <!--
                <p class="agreement">
                    <input type="checkbox" value=""/>
                    <label>I want to receive personalized offers by your site</label>
                </p>
                <p class="agreement">
                    <input type="checkbox" value=""/>
                    <label>Allow partners to send me personalized offers and related services</label>
                </p>
                -->
            </fieldset>
            <div><button class="button">Register &raquo;</button></div>
        </form>
    </body>
</html>


How to enable database cache in my java application

https://stackoverflow.com/questions/47004240/how-to-enable-database-cache-in-my-java-application


March 07, 2017

sample web application using ajax jquery - spring mvc


sample web application


JSP page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="css/branches.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript" src="js/branches.js" ></script>
</head>
<body>
<h1>listing</h1>
<div id="branchListDiv">
</div>
</body>
</html>

css page(css/branches.css)

table{
    
    border: 1px solid black;
    
}

js page(js/branches.js)


$(document).ready(function() {
var branches = ["Regional Office", "tsm nadakkavu", "zonal office"];
                        $('#branchListDiv').html('<div class="branch"><table width="400" height="80"><tr><th>TRIVENI SUPER MARKET NADAPURAM</th></tr><tr><td>NEAR BUSSTAND</td><td>400sqft</td><td rowspan="3">img</td></tr><tr><td>NADAPURAM POST</td><td>3000rent</td></tr><tr><td>PH:2345698</td></tr></table></div>');
                });



http://javabelazy.blogspot.in/

April 21, 2015

To call spring controller from ajax jquery in java spring

Ajax Jquery call to java spring controller


Description : The program will helps you to call java spring controller  from ajax jquery. To know spring configuration please refer this link. The link shows a  Hello world Model View Controller java spring example.

index.jsp


jquery api needed

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jqueryApps.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

These jquery api should be paste in your WEB-INF folder.


jqueryApps.js


function callJavaSpringController(){
var jqueryData = 'java spring mvc';
alert(senderEmail);

 $.ajax({
       type: "GET",
       url: "callcontroller.html",
       data: { message : jqueryData }
     }).done(function( msg ) {
       alert( "Data Saved: " + msg );
     });
}


JavaSpringSampleController.java


/**
JavaSpringSampleController  class
*/
package net.cfed.oms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.cfed.oms.model.SendMailModel;
import net.cfed.oms.service.EmployeeService;
import net.cfed.oms.serviceImpl.EmployeeServiceImpl;

import org.apache.catalina.connector.Request;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author free source codes
 *
 */
@Controller
public class JavaSpringSampleController {

@RequestMapping("/callcontroller")
public ModelAndView helloWorld(HttpServletRequest request, HttpServletResponse response) {

String message = "Welcome  to";
                message = message + request.getParameter("message");
System.out.println(message);
return new ModelAndView("index", "message", message);
}
}


Here is a sample for ajax jquery call to servlet , click on the link

http://javabelazy.blogspot.in/

January 28, 2015

Java Spring MVC hello World Example in Eclipse


Java Spring Model View Controller Hello World Example in Eclipse


Description : In this post we are sharing only source code for java spring application, For theoretical note you can refer this site I could nt provide a better description on java spring than this. Please note the deployment descriptor (web.xml) where we had provide the name index.jsp as our welcome file.

index page (index.jsp)

<html>
<head>
 <title>Office Management System</title>
</head>
<body>
<a href="hello.html">Click here</a>
</body>
</html>

Deployment Descriptor (web.xml)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>CfedOMS</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>


spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
       <context:component-scan base-package="net.cfed.oms.controller" />
   <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

JSTL (Java Standard Tag Library) : Expression Language ( EL) makes it possible to easy access application data stored in java bean.
Format : ${expression}

hello.jsp

<html>
<head> <title> This is my First application in Java Spring MVC </title></head>
<body>  ${message} </body>
</html>

What and Why annotation in java ?
Annotation allows implemented class to be auto-detected during class path spanning.
format : @component

RequestMapping is most used annotation method in java spring. It is used to map web request to a specific handler method. Here ModelAndViewHelloWorld Method. This concept is similar to java jsp servlets

Controller it indicates that the annotated class is a controller i e a web controller. 

HelloworldController.java

package net.cfed.oms.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {
        String message = "Hello, This is my first sample spring MVC project !";
        System.out.println(message);
        return new ModelAndView("hello", "message", message);
    }

}


Project structure


Why should i choose java spring ?
Once you configured java spring, you can easily work on the business logic of your application.

http://javabelazy.blogspot.in/

January 09, 2013

Image comparison in java using RGB value


How to compare (RGB value) two images using java


This example helps you to compare two images (either jpeg or png) using pixel. first the program check whether two images are of equal breadth and width, then it compare each pixel by pixel and return the output. The program will check whether the two images given resembles each other or not. This is one of the simplest way and pixel based.


package image.analysis.comparison;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/*
*  Image comparison done here is using pixels
*
*/

public class ImageComparison {
   
   
    public boolean compareTwoImages(File fileOne, File  fileTwo) {
        Boolean isTrue = true;
        try{
            Image imgOne = ImageIO.read(fileOne);
            Image imgTwo = ImageIO.read(fileTwo);
            BufferedImage bufImgOne = ImageIO.read(fileOne);
            BufferedImage bufImgTwo = ImageIO.read(fileTwo);
            int imgOneHt = bufImgOne.getHeight();
            int imgTwoHt = bufImgTwo.getHeight();
            int imgOneWt = bufImgOne.getWidth();
            int imgTwoWt = bufImgTwo.getWidth();
            if(imgOneHt!=imgTwoHt ||(imgOneWt!=imgTwoWt)){
                System.out.println(" size are not equal ");
                isTrue = false;
            }
            for(int x =0; x< imgOneHt; x++ ){
                for(int y =0; y <imgOneWt ; y++){
                    if(bufImgOne.getRGB(x, y) != bufImgTwo.getRGB(x, y) ){
                        System.out.println(" size are not equal ");
                        isTrue = false;
                        break;
                    }
                }
            }
        }catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return isTrue;
    }
   
   
    public static void main(String[] args) {
       
        File f = new File("E:\\javaaptitude\\Oracle.jpeg");
        File f2 = new File("E:\\javaaptitude\\Capgemini.jpeg");
        ImageComparison imgComp = new ImageComparison();
        System.out.println(imgComp.compareTwoImages(f, f2));
       
    }
   

}


The above code is for image having same width and height, if the image height and width is different use this code


package Bluetick;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class ImageComparison {
  
  
    public boolean compareTwoImages(File fileOne, File  fileTwo) {
        Boolean isTrue = true;
        try{
            Image imgOne = ImageIO.read(fileOne);
            Image imgTwo = ImageIO.read(fileTwo);
            BufferedImage bufImgOne = ImageIO.read(fileOne);
            BufferedImage bufImgTwo = ImageIO.read(fileTwo);
            int imgOneHt = bufImgOne.getHeight();
            int imgTwoHt = bufImgTwo.getHeight();
            int imgOneWt = bufImgOne.getWidth();
            int imgTwoWt = bufImgTwo.getWidth();
            if(imgOneHt!=imgTwoHt ||(imgOneWt!=imgTwoWt)){
                System.out.println(" size are not equal ");
                isTrue = false;
            }

            for(int x =0; x < imgOneWt; x++ ){ //replace the loop, if needed
                for(int y =0; y < imgOneHt ; y++){
                    if(bufImgOne.getRGB(x, y) != bufImgTwo.getRGB(x, y) ){
                        System.out.println(" rgb are not equal ");
                        isTrue = false;
                        break;
                    }
                }
            }
        }catch (IOException e) {
                        e.printStackTrace();
        }
        return isTrue;
    }
  
  
    public static void main(String[] softwareEngineer) {
      
        File OracleJava = new File("C:\\Image\FingerPrint\analysis.jpg");
        File javaOracle = new File("C:\\Histogram\match\image.jpg");
        ImageComparison imgComp = new ImageComparison();
        System.out.println(imgComp.compareTwoImages( OracleJava , javaOracle));
      
    }
  

}

from comments :-

To work the above code for different dimensional images the for loop has to replaced.

Change the for loop to the following .... for(int x =0; x < imgOneWt; x++ ){ for(int y =0; y < imgOneHt ; y++){ if(bufImgOne.getRGB(x, y) != bufImgTwo.getRGB(x, y) ){ System.out.println(" size are not equal "); isTrue = false; break; } } }


Hope you had tried the above code. Read this for to know how to create a captcha image in java : java be lazy

Thanks all for your valuable feed backs,

+jerin v george





http://javabelazy.blogspot.in/

August 21, 2012

To call external css class using jquery

How to call an external css class using jquery.

There are two ways to apply css through jquery

addClass("your css class name");

addClass will only append the new class to the existing one. so we have to remove the existing class using removeClass(" your css class name") method.

removeClass() is used to remove all the css class.

css() is used to apply style to a specific html component.

How to ?

html : file.html
<p id="powerballNumbers"> Hunger Games, Newsweek, </p>
<div id ="RioDeJaneiro" class ="McllroyClass"></div>

jquery : file.js
$("#powerballNumbers").css({"background":"yellow"});
$("#RioDeJaneiro").removeClass("McllroyClass").addClass("rihana");

css: file.css
.rihana
{
width : 10px;
height : 5 px;
backgroud : url (img_mileycyrus.gif) 0 0;
}

How to create a web application with jquery :  a simple web application

http://belazy.blog.com/

August 09, 2012

ajax jquery call to servlet example

How to call a servlet using jquery ajax

Description : This is a small example to call servlet using ajax jquery. also shows servlet mapping in web.xml file (Deployment descriptor) .How to use external javascript file in java[ajax servlet Tutorial].








web.xml

<servlet>
    <description></description>
    <display-name>AjaxServlet</display-name>
    <servlet-name>AjaxServlet</servlet-name>
    <servlet-class>servlets.AjaxServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AjaxServlet</servlet-name>
    <url-pattern>/AjaxServlet</url-pattern>
  </servlet-mapping>

 <welcome-file>index.jsp</welcome-file>


index.jsp

jquery api needed

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="myJquery.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

<div>
<input type="text" id="headText">
<input type="button" id="newButton" value="sendData">
</div>



servlet : AjaxServlet.java

public class AjaxServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AjaxServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(" inside do post "+request.getParameter("message"));
    }

}

jquery file : myjquery.js

$(document).ready(function(){
  $('#newButton').click(function(){
           sendData();
    });
   });
function sendData(){
   var mge = $('#newText').val();
    alert(mge);
    $.ajax({
        type: "POST",
        url: "AjaxServlet",
        data: { message : mge  }
      }).done(function( msg ) {
        alert( "Data Saved: " + msg );
      });
}

Description : The Example show how to call a servlet from jsp using ajax jquery. Data from jsp page will pass to servlet as parameter through ajax call


To receive response from the servlet, Change the code to following

In servlet

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws    ServletException, IOException {
        String message = request.getParameter("message");
         String respMess = message + "data saved ";
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(respMess);
    }

In jquey

The function sendData() will send data to post method of servlet "JqueryServlet". the data is taken from html tag whose id is " headText ". In the example i have created a text box named headtext in Index.jsp (java server page)

function sendData(){
    var mge = $('#headText').val();
   
    $.ajax({
          type: "POST",
          url: "JQueryServlets",
          data: { message : mge},
          success : function(data){
              alert('success'+data);
          }
        });
   
}



Thanking you for reading this post. Hope you will try the code...

Your feedback may help rest of the readers... so please, your valuable comments


Now take a look how cascading style sheet is applied in struts, that is a constant look and feel for all your web pages in your web application . >>> lazy java

Sunday Times 1 Bestseller New York Times 1 Bestseller the global bestseller - Origin is the latest Robert Langdon novel from the author of the Da Vinci Code. 'Fans will not be disappointed' the Times Robert Langdon, Harvard professor of symbology and religious iconology, arrives at the Guggenheim Museum Bilbao to attend the unveiling of an astonishing scientific breakthrough. The evening’s host is billionaire Edmond Kirsch, a futurist whose dazzling high-tech inventions and audacious predictions have made him a controversial figure around the world. But Langdon and several hundred guests are left reeling when the meticulously orchestrated evening is suddenly blown apart. There is a real danger that Kirsch’s precious discovery may be lost in the ensuing chaos. With his life under threat, Langdon is forced into a desperate bid to escape Bilbao, taking with him the museum’s director, Ambra Vidal. Together they flee to Barcelona on a perilous quest to locate a cryptic password that will unlock Kirsch’s secret. To evade a devious enemy who is one step ahead of them at every turn, Langdon and Vidal must navigate the labyrinthine passageways of extreme religion and hidden history. On a trail marked only by enigmatic symbols and elusive modern art, Langdon and Vidal will come face-to-face with a breathtaking truth that has remained buried – until now. ‘Dan Brown is the master of the intellectual cliffhanger’ Wall Street Journal ‘As engaging a hero as you could wish for’ Mail on Sunday ‘For anyone who wants more brain-food than thrillers normally provide’ Sunday Times

By Now Hurry- origin by dan brown


Author : +belazy

August 05, 2012

Ajax Java Servlet Example

How Ajax works with java example 

Introducing AJAX : asynchronous java and xml for Java web application , Here is a simple example
The below example shows you how java servlet response/replies to ajax request/call from a jsp page. The java server page need not be reload again, only the div refresh. Please try the source code.


Deployement Descriptor : web.xml




 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Java ajax call</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>nextgeneration.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ForAjax</display-name>
    <servlet-name>ForAjax</servlet-name>
    <servlet-class>ForAjax</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ForAjax</servlet-name>
    <url-pattern>/ForAjax</url-pattern>
  </servlet-mapping>
</web-app>



XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX  

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Nexegen Technologies</title>
<script type="text/javascript" src="ajax.js"></script>

</head>
<body>

<div id="ajaxDiv">
</div>

<div id = "mydiv">
<input type="button" onclick="verifyPassword()">
</div>

</body>
</html>

XXX XXX XXX XXX XXX XXX XXX XXX XXX


Ajax.js
/*
 * creates a new XMLHttpRequest object which is the backbone of AJAX,
 * or returns false if the browser doesn't support it
 */
function getXMLHttpRequest() {
  var xmlHttpReq = false;
  // to create XMLHttpRequest object in non-Microsoft browsers
  if (window.XMLHttpRequest) {
    xmlHttpReq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      // to create XMLHttpRequest object in later versions
      // of Internet Explorer
      xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (exp1) {
      try {
        // to create XMLHttpRequest object in older versions
        // of Internet Explorer
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (exp2) {
        xmlHttpReq = false;
      }
    }
  }
  return xmlHttpReq;
}
/*
 * AJAX call starts with this function
 */
function verifyPassword() {
  var xmlHttpRequest = getXMLHttpRequest();
  xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest);
  xmlHttpRequest.open("POST", "ForAjax", true);
  xmlHttpRequest.setRequestHeader("Content-Type",
      "application/x-www-form-urlencoded");
  xmlHttpRequest.send(null);
}

/*
 * Returns a function that waits for the state change in XMLHttpRequest
 */
function getReadyStateHandler(xmlHttpRequest) {

  // an anonymous function returned
  // it listens to the XMLHttpRequest instance
  return function() {
    if (xmlHttpRequest.readyState == 4) {
      if (xmlHttpRequest.status == 200) {
        document.getElementById("ajaxDiv").innerHTML = xmlHttpRequest.responseText;
      } else {
        alert("HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText);
      }
    }
  };
}
XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
servlet class :ForAjax


import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ForAjax
 */
public class ForAjax extends HttpServlet {
    private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ForAjax() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(" Konzern .... ");
        response.setContentType("text/html");
        response.getWriter().write(" success");
    }

}
 
simple ajax example
           
Thanking you....
for more

Facebook comments