0

我想通过在 .properties 文件中编写 userEmail、userPassword 和 userRole 来进行注册,然后在 auth-config.xml 中使用它们。所以,我在 loginManagerBean 中做这个:我知道注册方法中的代码重复,我会修复它

public void register(String Remail, String Rpassword, String Rrole) throws InvalidUserException{
    Properties prop = new Properties();
    InputStream in = getClass().getResourceAsStream("auction-roles.properties");
    try {
        prop.load(in);
        prop.setProperty(Remail,Rrole);
        prop.store(new FileOutputStream("auction-roles.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Properties prop2 = new Properties();
    InputStream in2 = getClass().getResourceAsStream("auction-users.properties");
    try {
        prop2.load(in2);
        prop2.setProperty(Remail,Rpassword);
        prop2.store(new FileOutputStream("auction-users.properties"), null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    login(Remail,Rpassword);

}

LoginManager 是一个命名的、会话范围的、有状态的 bean.. 问题是登录是 WORKING,但在注册时:

<h:commandButton id="registerButton" value="register"
        action="#{loginManager.register(registerEmail, registerPassword, registerRole)}"/>

单击注册按钮后出现此错误:

javax.servlet.ServletException: javax.el.MethodNotFoundException: /templates/register.xhtml @34,86 action="#{loginManager.register(registerEmail, registerPassword, registerRole)}": Method not found: class org.auction.LoginManager$244422980$Proxy$_$$_Weld$EnterpriseProxy$.register(java.lang.String, java.lang.String, java.lang.String)
4

1 回答 1

1

通过 f:param 传递参数

    <h:commandButton id="registerButton" value="register" action="#{loginManager.register} />
        <f:param name="regEmail" value="registerEmail" />
        <f:param name="regPwd" value="registerPassword" />
        <f:param name="regRole" value="registerRole" />
     </h:commandButton>

在托管 bean 方法中获取这样的值

public void register(){ 

Map<String, String> resMap = (Map<String, String>) externalContext.getRequestParameterMap();
String Remail= parameterMap.get("regEmail");
String Rpassword= parameterMap.get("regPwd");
String Rrole= parameterMap.get("regRole");

         Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream("auction-roles.properties");
try {
    prop.load(in);
    prop.setProperty(Remail,Rrole);
    prop.store(new FileOutputStream("auction-roles.properties"), null);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Properties prop2 = new Properties();
InputStream in2 = getClass().getResourceAsStream("auction-users.properties");
try {
    prop2.load(in2);
    prop2.setProperty(Remail,Rpassword);
    prop2.store(new FileOutputStream("auction-users.properties"), null);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

login(Remail,Rpassword);

      }
于 2017-02-14T05:05:21.990 回答