⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logincontroller.jpf

📁 jsp版 音乐站点 j2ee+weblogic
💻 JPF
字号:
package login;

import com.bea.wlw.netui.pageflow.FormData;
import com.bea.wlw.netui.pageflow.Forward;
import com.bea.wlw.netui.pageflow.PageFlowController;
import java.util.Iterator;

import javax.servlet.http.*;
import javax.security.auth.login.*;
import music.web.AccountManageBD;

/**
 * @jpf:controller
 * @jpf:view-properties view-properties::
 * <!-- This data is auto-generated. Hand-editing this section is not recommended. -->
 * <view-properties>
 * <pageflow-object id="pageflow:/login/LoginController.jpf"/>
 * <pageflow-object id="action:begin.do">
 *   <property value="60" name="x"/>
 *   <property value="40" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="action:login.do#login.LoginController.LoginForm">
 *   <property value="180" name="x"/>
 *   <property value="180" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="action:logout.do">
 *   <property value="300" name="x"/>
 *   <property value="40" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="action-call:@page:loginForm.jsp@#@action:login.do#login.LoginController.LoginForm@">
 *   <property value="96,120,120,144" name="elbowsX"/>
 *   <property value="171,171,171,171" name="elbowsY"/>
 *   <property value="East_1" name="fromPort"/>
 *   <property value="West_1" name="toPort"/>
 * </pageflow-object>
 * <pageflow-object id="page:loginForm.jsp">
 *   <property value="60" name="x"/>
 *   <property value="180" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="action-call:@page:success.jsp@#@action:logout.do@">
 *   <property value="300,300,300,300" name="elbowsX"/>
 *   <property value="135,110,110,85" name="elbowsY"/>
 *   <property value="North_1" name="fromPort"/>
 *   <property value="South_1" name="toPort"/>
 * </pageflow-object>
 * <pageflow-object id="page:success.jsp">
 *   <property value="300" name="x"/>
 *   <property value="180" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="action-call:@page:failure.jsp@#@action:begin.do@">
 *   <property value="144,120,120,96" name="elbowsX"/>
 *   <property value="31,31,31,31" name="elbowsY"/>
 *   <property value="West_1" name="fromPort"/>
 *   <property value="East_1" name="toPort"/>
 * </pageflow-object>
 * <pageflow-object id="page:failure.jsp">
 *   <property value="180" name="x"/>
 *   <property value="40" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="page:logout.jsp">
 *   <property value="420" name="x"/>
 *   <property value="40" name="y"/>
 * </pageflow-object>
 * <pageflow-object id="forward:path#success#loginForm.jsp#@action:begin.do@">
 *   <property value="60,60,60,60" name="elbowsX"/>
 *   <property value="85,110,110,135" name="elbowsY"/>
 *   <property value="South_1" name="fromPort"/>
 *   <property value="North_1" name="toPort"/>
 *   <property value="success" name="label"/>
 * </pageflow-object>
 * <pageflow-object id="forward:path#success#success.jsp#@action:login.do#login.LoginController.LoginForm@">
 *   <property value="216,240,240,264" name="elbowsX"/>
 *   <property value="171,171,171,171" name="elbowsY"/>
 *   <property value="East_1" name="fromPort"/>
 *   <property value="West_1" name="toPort"/>
 *   <property value="success" name="label"/>
 * </pageflow-object>
 * <pageflow-object id="forward:path#failure#failure.jsp#@action:login.do#login.LoginController.LoginForm@">
 *   <property value="180,180,180,180" name="elbowsX"/>
 *   <property value="135,110,110,85" name="elbowsY"/>
 *   <property value="North_1" name="fromPort"/>
 *   <property value="South_1" name="toPort"/>
 *   <property value="failure" name="label"/>
 * </pageflow-object>
 * <pageflow-object id="forward:path#success#logout.jsp#@action:logout.do@">
 *   <property value="336,360,360,384" name="elbowsX"/>
 *   <property value="31,31,31,31" name="elbowsY"/>
 *   <property value="East_1" name="fromPort"/>
 *   <property value="West_1" name="toPort"/>
 *   <property value="success" name="label"/>
 * </pageflow-object>
 * <pageflow-object id="formbeanprop:login.LoginController.LoginForm#username#java.lang.String"/>
 * <pageflow-object id="formbeanprop:login.LoginController.LoginForm#password#java.lang.String"/>
 * <pageflow-object id="formbean:login.LoginController.LoginForm"/>
 * </view-properties>
 * ::
 */
public class LoginController extends PageFlowController
{
    public String errorMessage = null;

    // Uncomment this declaration to access Global.app.
    // 
    //     protected global.Global globalApp;
    // 

    // For an example of page flow exception handling see the example "catch" and "exception-handler"
    // annotations in {project}/WEB-INF/src/global/Global.app

    /**
     * This method represents the point of entry into the pageflow
     * @jpf:action
     * @jpf:forward name="success" path="loginForm.jsp"
     */
    protected Forward begin()
    {
        return new Forward("success");
    }

    /**
     * @jpf:action
     * @jpf:forward name="success" path="success.jsp"
     * @jpf:forward name="failure" path="failure.jsp"
     */
    protected Forward login(LoginForm form)
    {
        String username = form.getUsername();
        String password = form.getPassword();

        /*
        WebCallbackHandler callbackHandler = new WebCallbackHandler(username, password);
        try {
            LoginContext loginContext = new LoginContext("music_jaas.config", callbackHandler);
            loginContext.login();
            getSession().setAttribute("LoginContext", loginContext);
            System.out.println("-- Loign successfully: Principals --");
            Iterator it = loginContext.getSubject().getPrincipals().iterator();
            while(it.hasNext())
                System.out.println(it.next().toString());
        }
        catch(LoginException le) {
            this.errorMessage = le.getMessage();
            return new Forward("failure");
        }
        */

        AccountManageBD accountBD = (AccountManageBD)getSession().getAttribute(AccountManageBD.ACCOUNT);
        try {
            accountBD.login(username, password);
        }
        catch(Exception e) {
            this.errorMessage = e.getMessage();
            return new Forward("failure");
        }
        return new Forward("success");
    }

    /**
     * @jpf:action
     * @jpf:forward name="success" path="logout.jsp"
     */
    protected Forward logout()
    {
        AccountManageBD accountBD = (AccountManageBD)getSession().getAttribute(AccountManageBD.ACCOUNT);
        accountBD.logout();

        return new Forward("success");
    }

    /**
     * FormData get and set methods may be overwritten by the Form Bean editor.
     */
    public static class LoginForm extends FormData
    {
        private String username;
        private String password;

        public String getUsername() { return this.username; }
        public void setUsername(String username) { this.username = username; }

        public String getPassword() { return this.password; }
        public void setPassword(String password) { this.password = password; }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -