開源 java CMS - FreeCMS商業版在模板中增長後臺管理員登陸功能

項目地址:http://www.freeteam.cn/ javascript

 

在須要添加登陸功能頁面模板中添加如下代碼 html

<span id="adminSpan"> java

<@ajaxLoad targetid="adminSpan" url="/site/${site.sourcepath}/admin.fhtml" ;code>${code}</@ajaxLoad> jquery

</span> ajax

 

此方法用到了ajax須要引入jquery.js session

引入方法 jsp

<script type="text/javascript" src="${contextPath}js/jquery-1.5.1.min.js"></script> post

 

在模板目錄下建立admin.html模板文件,代碼以下 this

 

<!-- 這是基本的功能,須要其它的能夠本身添加 --> url

<#if session_loginAdmin??>

<!-- 已登陸 -->

${session_loginAdmin.loginname}

<a href="${contextPath}logout.do">退出</a>

<#else>

<!-- 未登陸 -->

<script>

 

            function formSubmit(){

                                     if($.trim($("#username").val())==""){

                                               alert("請輸入用戶名!");

                                               return false;

                                     }

                                     if($.trim($("#password").val())==""){

                                               alert("請輸入密碼!");

                                               return false;

                                     }

                                     if($.trim($("#ValidateCode").val())==""){

                                               alert("請輸入驗證碼!");

                                               return false;

                                     }

                                               var data="loginname="+$("#username").val()+"&pwd="+$("#password").val()

                                               +"&ValidateCode="+$("#ValidateCode").val();

                                               $.post("${contextPath}login.do",data,loginComplete,"text");

                     return false;

            }

                            function loginComplete(data){

                                     if(""==data){

                                    

                       $.get('/site/demo/admin.fhtml',{},ajaxLoadCompleteAdmin,'text');function ajaxLoadCompleteAdmin(data){$('#adminSpan').html(data);}

                                     }else{

                                               alert(data);

                                     }

                            }

</script>

<form  action="${contextPath}login.do" method="post" onSubmit="return formSubmit();">

         用戶名<input type="text" id="username" name="loginname" placeholder="用戶名">

密碼<input type="password" id="password" name="pwd" placeholder="密碼">

驗證碼<input type="text" id="ValidateCode" name="ValidateCode" style="width:50px" maxlength="4" placeholder="驗證碼">

      <img src="${contextPath}image.jsp" title="點擊從新獲取驗證碼" style="cursor:hand" onclick="this.src='${contextPath}image.jsp?date='+new Date();"/>

    

        <button class="btn btn-block btn-large btn-primary"  type="submit"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>

  </form>

 

</#if>

相關文章
相關標籤/搜索