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

原文地址:http://javaz.cn/site/javaz/site_study/info/2016/44988.html javascript

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

在模板中增長會員登陸功能 java

 

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

<span id="memberSpan"> ajax

<@ajaxLoad targetid="memberSpan" url="/site/${site.sourcepath}/member.fhtml" ;code>${code}</@ajaxLoad> session

</span> jsp

 

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

引入方法 this

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

 

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

 

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

<#if session_loginMember??>

<!-- 已登陸 -->

${session_loginMember.loginname}

  <a href="${contextPath}mlogout.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}mlogin.do",data,loginComplete,"text");

                     return false;

            }

                            function loginComplete(data){

                                     if(""==data){

                                                        $.get('/site/demo/member.fhtml',{},ajaxLoadCompleteMember,'text');function ajaxLoadCompleteMember (data){$('# memberSpan').html(data);}

                                     }else{

                                               alert(data);

                                     }

                            }

</script>

<form  action="${contextPath}mlogin.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>

相關文章
相關標籤/搜索