页面加载前实现调整(实现伪单点登录)

10 篇文章 0 订阅
1、编写一个简单页面,将登录的信息隐藏在一个DIV里面
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:form id="f1">
        <af:resource type="javascript">
          function addLoginInfo() {
              document.getElementById("wsLogin").submit();
          }
        </af:resource>
      </af:form>
      <af:outputText value="页面正在跳转中..." id="ot1" inlineStyle="font-size:14px;"/>
     
      <div style="display: none;">
        <form id="wsLogin" method="post" action="${pageFlowScope.composerUrl}/j_security_check"
              οnsubmit="return addLiginInfo()">
          <input type="hidden" value="utf-8" name="j_character_encoding"/>
          <table class="loginTable">
            <tfoot>
              <tr>
                <td>
                  <button type="submit" class="Button"
                          id="loginButton">登 录</button>
                </td>
              </tr>
            </tfoot>
            
            <tr>
              <th>用 户 名:</th>
              <td>
                <input type="text" id="username" name="j_username" class="input"
                       value="${pageFlowScope.username}"/>
              </td>
            </tr>
            
            <tr>
              <th>密  码:</th>
              <td>
                <input type="password" name="j_password" class="input" autocomplete="off"
                       value="${pageFlowScope.pwd}"/>
              </td>
            </tr>
          </table>
        </form>
      </div>
    </af:document>
  </f:view>
</jsp:root>
 
2、编写一个后台的backingBean类实现PagePhaseListener接口,将用户名密码取到后放入到作用域里,然后通过后台调用前台的JS代码来控制跳转。
 
import java.io.Serializable;

import javax.faces.context.FacesContext;

import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import oracle.adf.share.ADFContext;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class MailRedirect extends CustomManagedBean implements Serializable, PagePhaseListener {
    public MailRedirect() {
    }

    public void afterPhase(PagePhaseEvent pagePhaseEvent) {
    }

    public void beforePhase(PagePhaseEvent pagePhaseEvent) {
        if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
            GetDBInfoBean bean = new GetDBInfoBean();
            String currentUsername = ADFContext.getCurrent().getSecurityContext().getUserName();
            MailInfoBean mail = (MailInfoBean)bean.getMailInfoByUserName(currentUsername).get(0);
            String userName = mail.getMail();
            String password = mail.getPassword();
            this.setExpressionValue("#{pageFlowScope.uid}", userName);
            this.setExpressionValue("#{pageFlowScope.pwd}", password);
            FacesContext fctx = FacesContext.getCurrentInstance();
            ExtendedRenderKitService erks = null;
            erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
            String script = "addLoginInfo();";
            erks.addScript(fctx, script);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值