1 Reply Latest reply: Jul 29, 2013 11:02 AM by HiraMuntaha RSS

    Ajax request problem

    Prem

      Hi , I am writting a simple login application using Ext-js and servlet.

      I need , show login form , if ok then go to success page , with some list generated at server sider otherwise to error page.

       

      Using Ext.FormPanel , I am submitting form and request param using Ajax request.

       

      Problem is , I am able to submit a request , it is hitting to doPost() method of servlet , but when it comes back not redirected to any erropage or success page.

       

      following is the code of login.js, servlet and jsp . Please help me out.I am using Ext.js 3

       

      login.js

      Ext.ns('ediscovery');
      Ext.onReady(function() {
      
      
          var loginForm = Ext.extend(Ext.FormPanel, {
      
      
              id : 'loginForm',
              initComponent : function() {
                  //this.standardSubmit = true
                  this.title = 'Please login'
                  //this.url = '/MainController'
                  this.items = this.getPageItems();
                  this.padding = 30
                  this.buttons = this.getButtons();
                  this.bodyBorder = false
                  this.labelAlign = 'right'
                      this.width = 350
                  this.style = { marginLeft : '850px',marginRight:'50px',marginTop:'100px'}   
                  loginForm.superclass.initComponent.call(this);
              },
              getPageItems : function() {
                  var items = [];
                  var userNameField = new Ext.form.TextField({
                      name : 'userName',
                      id : 'userName',
                      fieldLabel : 'User Name'
                      //,anchor : '60% 6%'
                      ,allowBlank : false   
                      ,blankText : 'This field is required'
                      ,value:'eediscoverycloud'
                  });
      
      
                  var passwordField = new Ext.form.TextField({
                      name : 'testname',
                      fieldLabel : 'Password',
                      id : 'password',
                      inputType : 'password'
                      //,anchor : '60% 6%'
                      ,allowBlank : false   
                      ,blankText : 'This field is required'
                      ,value:'parse@123'
                  });
                 
                 
                 
      
      
                  items.push(userNameField);
                  items.push(passwordField);
                  return items;
              }
              ,getButtons : function(){
                  var buttons = [];
                 
                  var submitBtn = new Ext.Button({
                      text : 'Submit'
                      ,handler : function(){
                          var userName = Ext.getCmp('userName').getValue();
                          var password = Ext.getCmp('password').getValue();
                          console.log("User Name : "+userName);
                          console.log("Password : "+password);
                          var cmp = Ext.getCmp('loginForm');
                          //cmp.getEl().mask("Processing");
                          /*var fp = this.ownerCt.ownerCt;
                          fp.getForm().submit();*/
                          Ext.Ajax.request({
                              url:"MainController"
                              ,method : 'post'
                              ,params : "userName="+userName+"&password="+password
                              /*,success : function(response,option){
                                  console.log(response);
                                  Ext.Msg.alert('Status', 'Orders Saved successfully.');
                                  cmp.getEl().unmask();
                                 
                              }
                              ,failure : function(response,option){
                                  console.log(response);
                                  Ext.Msg.alert('Status', 'Some error occured. Please contact to Administrator');
                                  cmp.getEl().unmask();
                              }*/
                          })
                      }
                  })
                 
                  var resetBtn = new Ext.Button({
                      text : 'Reset'
                  })
                 
                  buttons.push(submitBtn);
                  buttons.push(resetBtn);
                 
                  return buttons;
                 
              }
      
      
          });
         
          
          new Ext.Viewport({
              resizable: false
              ,items : [new loginForm()]
          });
         
      
      
      });
      
      
      
      

       

       

       

       

       

      servlet

       

       

      package com.ediscoverycloud.controller;
      
      
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.io.StringWriter;
      import java.util.Iterator;
      import java.util.List;
      
      
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      
      import com.ediscoverycloud.util.DocWriter;
      import com.ediscoverycloud.util.Order;
      import com.ediscoverycloud.util.ReadMail;
      
      
      /**
      * Servlet implementation class MainController
      */
      public class MainController extends HttpServlet {
          private static final long serialVersionUID = 1L;
            
          /**
           * @see HttpServlet#HttpServlet()
           */
          public MainController() {
              super();
              // TODO Auto-generated constructor stub
          }
      
      
      
      
          /**
           * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
           */
          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              String userName = request.getParameter("userName");
              String password = request.getParameter("password");
              request.getRequestDispatcher("/error").forward(request, response);
              System.out.println("Done");
          }
      
      
      }
      
      
      
      

       

       

       

      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>eDiscoveryCloudWeb</display-name>
        <welcome-file-list>
          <welcome-file>index.html</welcome-file>
          <welcome-file>index.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>MainController</display-name>
          <servlet-name>MainController</servlet-name>
          <servlet-class>com.ediscoverycloud.controller.MainController</servlet-class>
        </servlet>
        <servlet-mapping>
          <servlet-name>MainController</servlet-name>
          <url-pattern>/MainController</url-pattern>
        </servlet-mapping>
      
      <servlet>
            <servlet-name>Error Page</servlet-name>
            <jsp-file>/errorPage.jsp</jsp-file>
        </servlet>
      
        <servlet-mapping>
            <servlet-name>Error Page</servlet-name>
            <url-pattern>/error</url-pattern>
        </servlet-mapping>
      
      
      
      
      </web-app>