1. #1
    Ext JS Premium Member
    Join Date
    Nov 2008
    Posts
    51
    Vote Rating
    0
    DesmoDevil is on a distinguished road

      0  

    Question Looking for a simple AJAX JSP/servlet example

    Looking for a simple AJAX JSP/servlet example


    Anyone have a simple example of how to send success and failure back to the client EXT application?

    I see how to set up the client side, but I havent seen a simple "hello world"type jsp or servlet that processes the client info and sends a response back.

    Anyone have one? Or just some example code snippet you have?

    thanks all

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    response.getWriter().print("{success: true}");

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2008
    Posts
    51
    Vote Rating
    0
    DesmoDevil is on a distinguished road

      0  

    Default


    Thanks animal...got a an example of how to return an error message with that?

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    response.getWriter().print("{success: true, errorMessage: 'Error'}");

  5. #5
    Ext User
    Join Date
    May 2009
    Posts
    1
    Vote Rating
    0
    BinodSuman is on a distinguished road

      0  

    Default Ajax programming with Servlet

    Ajax programming with Servlet


    I have written one simple Ajax program using servlet response. I searched a lot over net, but couldnt get any easy example. So, I have posted that
    simple ajax program at my blog.

    http://binodsuman.blogspot.com/2009/...x-siimple.html

    Thanks,

    Binod Suman
    http://binodsuman.blogspot.com

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    That has nothing to do with Ext. It is an example of how difficult life if without Ext to do your Ajax, and create HTML for you.

    Do some research, and try again with an Ext solution!

  7. #7
    Ext User
    Join Date
    Jul 2008
    Posts
    41
    Vote Rating
    0
    Singha1 is on a distinguished road

      0  

    Default


    Use your JSP Code something like as below.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <%@ page
    language="java"
    contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    %>
    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <META name="GENERATOR" content="IBM WebSphere Studio">
    <META http-equiv="Content-Style-Type" content="text/css">
    <LINK href="theme/Master.css" rel="stylesheet" type="text/css">
    <TITLE>SaveName.jsp</TITLE>
    </HEAD>
    <BODY>
    <%
    response.setContentType("text/html");
    String str = request.getParameter("firstName");
    String str1 = request.getParameter("lastName");
    if(str.equalsIgnoreCase("amit")){
    response.getWriter().print("{'success': true}");

    }

    else{
    response.getWriter().print("{success: false, errorMessage: 'Error'}");

    }


    %>

    </BODY>
    </HTML>

    And use load() or Ext.ajax.request in Ext code.
    If you use load(), then use callback method to read the response.
    Like as below in your submit button code.

    function doSave(){
    var me = Ext.get('fName').dom.value;
    var m = Ext.get('test');
    Ext.Ajax.request({
    url:'SaveName.jsp',
    method:'GET',
    params:{
    firstName: me,
    lastName:'Singh',
    email: 'someParamValue'
    },
    success: function(o) {
    alert("Hi");

    alert(o.responseText);
    },
    failure: function(o){
    Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?');

    }
    })
    }

  8. #8
    Sencha User
    Join Date
    Aug 2012
    Posts
    1
    Vote Rating
    0
    programmingfree is on a distinguished road

      0  

    Default Simple AJAX JSP/Servel Example

    Simple AJAX JSP/Servel Example


    It is very simple to make AJAX calls to servlet from JSP using JQuery. Check this example.