2016-07-10 3 views
1

저는 ExtJS를 사용하여 새롭습니다. 내가 로그인 양식을 만들었습니다, 제출 매개 변수 값을 서블릿에 전달해야합니다. 서블릿이 호출되는 경우에도 값 전달은 null입니다. 아래에 코드 스 니펫을 첨부하여 오류 디버깅을 도와주십시오.서블릿에 전달 된 값이 extjs4.2.2에서 null로 - java 서블릿

login.js

Ext.application({ 
name: 'test-application', 
launch: function() { 

    Ext.QuickTips.init(); 

    var login_details = Ext.create('Ext.form.Panel', { 
     frame: true, 
     xtype: 'fieldset', 
     padding: 10, 
     layout: 'anchor', 
     fieldDefaults: { 
      msgTarget: 'side', 
      labelWidth: 50 
     }, 
     defaultType: 'textfield', 
     defaults: { 
      anchor: '100%' 
     }, 
     items: [{ 
       xtype: 'fieldset', 
       title: 'Login', 
       defaultType: 'textfield', 
       layout: 'anchor', 
       defaults: { 
        anchor: '100%' 
       }, 
       items: [{ 
         xtype: 'container', 
         columnWidth: 1, 
         layout: 'anchor', 
         items: [{ 
           xtype: 'textfield', 
           labelAlign: 'top', 
           fieldLabel: 'Username', 
           name: 'username', 
           id: 'username', 
           allowBlank: false, 
           padding: '0 0 10 0', 
           anchor: '60%' 
          }, { 
           xtype: 'textfield', 
           labelAlign: 'top', 
           fieldLabel: 'Password', 
           inputType: 'password', 
           name: 'password', 
           id:'password', 
           allowBlank: false, 
           padding: '0 0 10 0', 
           anchor: '60%' 
          }] 
        }] 
      }], 
     buttons: [{ 
       text: 'Login', 
       handler: function() 
       { 
        Ext.Ajax.request({ 
         url: '/TestSystem/LoginServlet', 
         method: 'POST' 
        }); 
        var formData = this.up('form').getForm(); 
        formData.submit(); 
       } 
      }, 
      { 
       text: 'Reset Form', 
       handler: function() { 
        this.up('form').getForm().reset(); 
       } 
      }] 
    }); 

    var login_panel = new Ext.Panel({ 
     region: 'center', 
     align: 'stretch', 
     title: 'Test Automation', 
     items: [login_details] 
    }); 

    Ext.create('Ext.container.Viewport', { 
     layout: 'fit', 
     items: [{ 
       layout: 'border', 
       defaults: { 
        collapsible: false, 
        collapsed: false, 
        split: false, 
        bodyStyle: 'padding:2px' 
       }, 
       items: [{ 
         region: 'north', 
         height: 150, 
         minSize: 75, 
         maxSize: 250, 
         cmargins: '0 0 0 0', 
         border: false 
        }, { 
         region: 'west', 
         width: 450, 
         minSize: 100, 
         maxSize: 250, 
         border: false 
        }, { 
         region: 'center', 
         align: 'stretch', 
         border: false, 
         layout: { 
          type: 'fit', 
          align: 'stretch' 
         }, 
         items: [login_panel] 
        }, 
        { 
         region: 'east', 
         width: 450, 
         minSize: 100, 
         maxSize: 150, 
         bodyStyle: 'padding:0px', 
         border: false 
        }, 
        { 
         region: 'south', 
         width: 225, 
         height: 300, 
         minSize: 100, 
         maxSize: 250, 
         bodyStyle: 'padding:0px', 
         border: false 
        } 
       ] 
      }], 
     renderTo: Ext.getBody() 
    }); 
} 
}); 

LoginServlet.java

package servlet; 

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

/** 
    * @author Bijoy 
*/ 

@WebServlet(description = "Servlet used to validate users", urlPatterns = { "/LoginServlet" }) 
public class LoginServlet extends HttpServlet { 

private static final long serialVersionUID = 1L; 

@Override 
protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 

    response.setContentType("text/html"); 

    String username = request.getParameter("username"); 
    String password = request.getParameter("password"); 
    System.out.println("Username from UI : " + username); 
    System.out.println("Password from UI : " + password); 
    } 
} 

내가 사용에 extjs-4.2.2

답변

0

양식을 제출하려면 아약스 요청이 필요하지 않습니다.

URL 설정을 사용하면 form.submit() 만 있으면됩니다.

제출 (옵션) : Ext.form.Basic 체인 가능 바로 가기는이 조치를 제출해야 할 일. 이것은 기본적으로 AJAX 제출 작업을 사용합니다. standardSubmit 구성을 사용하는 경우 표준 양식 요소 을 사용하여 제출하거나 api 구성이있는 경우 Ext.direct.Direct 제출 작업을 사용합니다.

var formData = this.up('form').getForm(); 
    formData .submit({ 
     clientValidation: true, 
     url: '/TestSystem/LoginServlet', 
     success: function(form, action) { 
      Ext.Msg.alert('Success', action.result.msg); 
     }, 
     failure: function(form, action) { 
      switch (action.failureType) { 
       case Ext.form.action.Action.CLIENT_INVALID: 
        Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values'); 
        break; 
       case Ext.form.action.Action.CONNECT_FAILURE: 
        Ext.Msg.alert('Failure', 'Ajax communication failed'); 
        break; 
       case Ext.form.action.Action.SERVER_INVALID: 
        Ext.Msg.alert('Failure', action.result.msg); 
      } 
     } 
    }); 
0

시도는 코드 아래

{ 
      text: 'Login', 
      handler: function() 
      { 
       var formData = this.up('form').getForm(); 
       formData.submit({ 
         url: '/TestSystem/LoginServlet', 
         method: 'POST', 
         success: function(form,action){ 
         // your success code once servelt returns response 
         }, 
         failure: function(form,action){ 
         } 

       }); 
      } 
와 핸들러 변경하고

자기 자신을 제출 aja 할 것이다 x 요청.

관련 문제