`
牧羊人
  • 浏览: 210751 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ext logon

阅读更多

<html>
<head>
    <title>供应商服务系统 V1.0</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="js/ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="js/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="js/ext/ext-all.js"></script>
    <script type="text/javascript" src="js/ext/build/locale/ext-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/logon.js"></script>
</head>

<body>

</body>
</html>




Ext.onReady(function(){
    Ext.QuickTips.init();
     Ext.form.Field.prototype.msgTarget = 'side';

    var login = new Ext.FormPanel({ 
        labelWidth:70,
        labelAlign :'right',
        frame:true,
        defaults: {width: 170},
        bodyStyle:'padding:10px 5px 0', 
        defaultType:'textfield',
        monitorValid:true,
        items:[{ 
                fieldLabel:'用户帐号', 
                name:'userId',
                emptyText:'请输入用户帐号',
                allowBlank:false
            },{ 
                fieldLabel:'用户密码', 
                name:'password', 
                inputType:'password', 
                allowBlank:false 
            }],

        buttons:[{ 
                text:'登录',
                formBind: true,    
                // Function that fires when user clicks the button 
                handler:function(){ 
                    login.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'系统提示', 
                        waitMsg:'正在登录,请稍候...',
                        url:'Logon.do',

            // Functions that fire (success or failure) when the server responds. 
            // The one that executes is determined by the 
            // response that comes from Logon.do as seen below. The server would 
            // actually respond with valid JSON, 
            // something like: response.write "{ success: true}" or 
            // response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}" 

                        success:function(){
                                var redirect = 'index.html'; 
                                window.location = redirect;
                        },

            // Failure function, see comment above re: success and failure. 
            // You can see here, if login fails, it throws a messagebox
            // at the user telling him / her as much. 

                        failure:function(form, action){ 
                            if(action.failureType == 'server'){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('登录失败', obj.errors.reason,function() {form.findField('userId').focus();}); 
                            }else{ 
                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText); 
                            }                            
                        } 
                    }); 
                } 
            }] 
    });


    // This just creates a window to wrap the login form. 
    // The login object is passed to the items collection.       
    var win = new Ext.Window({
        title:'用户登录', 
        layout:'fit',
        border:false,
        width:300,
        //height:160,
        closable: false,
        resizable: false,
        plain: true,
        items: [login]
    });    
    win.show();       

});






package com.linbq.servlet;

import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.linbq.bean.*;

/** *//**
* 用户登录操作响应控制
* <p>对用户登录等响应请求进行处理.</p>
* @author linbq
*/

public class LogonServlet extends HttpServlet
{        
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {            
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");        
        
        //安全性检查,防止非法操作Servlet
        if (userId == null || userId.length() == 0 || password == null || password.length() == 0) return;
        
        response.setContentType("text/xml;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");        
        PrintWriter out=response.getWriter();
        User user = new User();    
        if (user.logon(userId, password)) {
            HttpSession session = request.getSession(); 
            session.setAttribute("userId", user.getId());
            session.setAttribute("userName", user.getName());
            out.write("{ success: true}");
        } else {
            out.write("{ success: false, errors: { reason: '用户帐号或密码验证不通过.' }}");
        }
        out.close();
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        doGet(request, response);
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics