cas ajax+jsonp+iframe 实现无页面跳转

    xiaoxiao2026-05-25  4

    1.客户端

    html代码 < head >      < meta  charset = "utf-8" >      < title ></ title > </ head > < script  data-main = "script/main"  src = "script/require.js" ></ script > < script  type = "text/javascript" > var v = + +new Date; v = '1.0'; requirejs.config({      urlArgs: "v=" + v, }); function login(){      console.log("*****************登陆调用****************") } </ script > < body  entryJS = "cas" >      < form  action = "<a href="http://192.168.1.109:8080/cas/login?action=ajaxSubmit&loginFailURL=http://127.0.0.1:8080/svg/loginBackCall.html" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://192.168.1.109:8080/cas/login?action=ajaxSubmit&loginFailURL=http://127.0.0.1:8080/svg/loginBackCall.html"  name = "form1"  method = "post"  id = "loginForm"  target = "myIframe" >          < input  type = "text"  name = "username"  value = "casuser"  placeholder = "用户名"  class = "user"  id = "user_login" >          < input  type = "password"  name = "password"  value = "Mellon"  placeholder = "密码"  class = "pwd"  id = "pwd_login" >          < button  id = "submit_login" >登陆</ button >          < input  type = "text"  name = "lt"  id = "lt"  value = ""  />          < input  type = "text"  name = "execution"  id = "execution"  value = ""  />          < input  type = "text"  name = "_eventId"  value = "submit"  />      </ form >      < iframe  src = "javasscript:void(0);"  id = "myIframe"  name = "myIframe" ></ iframe > </ body > </ html > js代码 run:  function () {                          $( "#submit_login" ).click( function (){                              $.getJSON( "<a href="http://192.168.1.109:8080/cas/login?action=getlt&callback=?&service=http://127.0.0.1:8080/svg" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://192.168.1.109:8080/cas/login?action=getlt&callback=?&service=http://127.0.0.1:8080/svg" ,                                 function (data) {                                    $( "#execution" ).val(data.execution);                                 log.log($( "#execution" ).val());                                 $( "#lt" ).val(data.lt);                                 $( "#loginForm" ).submit();                              });                          });                                                }

    2.客户端修改casLoginView.jsp

    <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="<a href="http://java.sun.com/jsp/jstl/core" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="spring" uri="<a href="http://www.springframework.org/tags" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://www.springframework.org/tags" %> <%@ taglib prefix="form" uri="<a href="http://www.springframework.org/tags/form" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://www.springframework.org/tags/form" %> <%@ taglib prefix="fn" uri="<a href="http://java.sun.com/jsp/jstl/functions" "="" style="color: rgb(50, 108, 166); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: auto !important; background: none !important;">http://java.sun.com/jsp/jstl/functions" %> < c:choose >      < c:when  test = "${param.action !=null && param.action == 'getlt'}" >          <%          String action = request.getParameter("action");             String callbackName = request.getParameter("callback");           String jsonData = "{\"lt\":\"" + request.getAttribute("loginTicket") + "\", \"execution\":\"" + request.getAttribute("flowExecutionKey") + "\"}";           String jsonp = callbackName + "(" + jsonData + ")";                   response.setContentType("application/javascript");           response.getWriter().write(jsonp);           %>     </ c:when >     < c:when  test = "${param.action !=null && param.action == 'ajaxSubmit'}" >          < div  id = "msg" >              < c:forEach  var = "cook"  items = "${flowRequestContext.messageContext.allMessages}" >                   ${cook.text}             </ c:forEach >          </ div >          < script  type = "text/javascript" >              var msgObj = document.getElementById("msg");              var myMsg = msgObj.innerText;              var url ="${param.loginFailURL}?tag=0&msg="+myMsg              window.location.href=url;          </ script >          <!--          String action = request.getParameter("action");             String callbackName = request.getParameter("callback");           String jsonData = "{\"lt\":\"" + request.getAttribute("loginTicket") + "\", \"execution\":\"" + request.getAttribute("flowExecutionKey") + "\"}";           String jsonp = callbackName + "(" + jsonData + ")";                   response.setContentType("application/javascript");           response.getWriter().write(jsonp);            -->     </ c:when >       < c:otherwise >     < jsp:directive.include  file = "includes/top.jsp"  />          <!--    ${flowRequestContext}    // ${flowRequestContext.messageContext}    //    <br/>    <c:forEach var="cook" items="${flowRequestContext.messageContext.allMessages}">      ${cook.text}     </c:forEach>    -->                   < div  class = "box"  id = "login" >      < form:form  method = "post"  id = "fm1"  commandName = "${commandName}"  htmlEscape = "true" >          < form:errors  path = "*"  id = "msg"  cssClass = "errors"  element = "div"  htmlEscape = "false"  />          < h2 >< spring:message  code = "screen.welcome.instructions"  /></ h2 >          < section  class = "row" >              < label  for = "username" >< spring:message  code = "screen.welcome.label.netid"  /></ label >              < c:choose >                  < c:when  test = "${not empty sessionScope.openIdLocalId}" >                      < strong >< c:out  value = "${sessionScope.openIdLocalId}"  /></ strong >                      < input  type = "hidden"  id = "username"  name = "username"  value = "<c:out value=" ${sessionScope.openIdLocalId}" />" />                  </ c:when >                  < c:otherwise >                      < spring:message  code = "screen.welcome.label.netid.accesskey"  var = "userNameAccessKey"  />                      < form:input  cssClass = "required"  cssErrorClass = "error"  id = "username"  size = "25"  tabindex = "1"  accesskey = "${userNameAccessKey}"  path = "username"  autocomplete = "off"  htmlEscape = "true"  />                  </ c:otherwise >              </ c:choose >          </ section >          < section  class = "row" >              < label  for = "password" >< spring:message  code = "screen.welcome.label.password"  /></ label >                  <%--                  NOTE: Certain browsers will offer the option of caching passwords for a user.  There is a non-standard attribute,                  "autocomplete" that when set to "off" will tell certain browsers not to prompt to cache credentials.  For more                  information, see the following web page:                  http://www.technofundo.com/tech/web/ie_autocomplete.html                  --%>              < spring:message  code = "screen.welcome.label.password.accesskey"  var = "passwordAccessKey"  />              < form:password  cssClass = "required"  cssErrorClass = "error"  id = "password"  size = "25"  tabindex = "2"  path = "password"   accesskey = "${passwordAccessKey}"  htmlEscape = "true"  autocomplete = "off"  />              < span  id = "capslock-on"  style = "display:none;" >< p >< img  src = "images/warning.png"  valign = "top" > < spring:message  code = "screen.capslock.on"  /></ p ></ span >          </ section >          <!--          <section class="row check">              <p>                  <input id="warn" name="warn" value="true" tabindex="3" accesskey="<spring:message code="screen.welcome.label.warn.accesskey" />" type="checkbox" />                  <label for="warn"><spring:message code="screen.welcome.label.warn" /></label>                  <br/>                  <input id="publicWorkstation" name="publicWorkstation" value="false" tabindex="4" type="checkbox" />                  <label for="publicWorkstation"><spring:message code="screen.welcome.label.publicstation" /></label>                  <br/>                  <input type="checkbox" name="rememberMe" id="rememberMe" value="true" tabindex="5"  />                  <label for="rememberMe"><spring:message code="screen.rememberme.checkbox.title" /></label>              </p>          </section>          -->          < section  class = "row btn-row" >              < input  type = "hidden"  name = "lt"  value = "${loginTicket}"  />              < input  type = "hidden"  name = "execution"  value = "${flowExecutionKey}"  />              < input  type = "hidden"  name = "_eventId"  value = "submit"  />              < input  class = "btn-submit"  name = "submit"  accesskey = "l"  value = "<spring:message code=" screen.welcome.button.login" />" tabindex="6" type="submit" />              < input  class = "btn-reset"  name = "reset"  accesskey = "c"  value = "<spring:message code=" screen.welcome.button.clear" />" tabindex="7" type="reset" />          </ section >      </ form:form > </ div > < jsp:directive.include  file = "includes/bottom.jsp"  />     </ c:otherwise >  </ c:choose >
    转载请注明原文地址: https://ju.6miu.com/read-1310044.html
    最新回复(0)