0

データベースからユーザー名とパスワードをチェックするログインページを作成しようとしています。送信ボタンをクリックするとすぐに、ウェルカムページではなくwelcome.xhtmlファイルのコードが表示されます。誰かがこの問題を解決する方法を教えてもらえますか?

フェイスレットを使用するようにlogin.xhtmlに変更を加えた後も、同じ問題が発生します。

login.xhtml:

<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">  

    <h:body>

      <h:form>

          <p>
              <h:inputText
                  id="username"
                  title="Username"
                  value="#{userBean.username}">

              <h:inputText
                  id="password"
                  title="Password"
                  value="#{userBean.password}">
              </h:inputText>

              <h:commandButton id="submit" value="Submit" action="#{userBean.validate}"/>
          </p>

      </h:form>
  </h:body>

マネージドBean:

@Stateless
public class userBean implements Serializable {

    private String username, password;
    private String response = "";
    private UserFacade userFacade;

    public userBean() {
    }

    public String getPassword() {
        return password;
    }

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

    public String getUserName() {
        return username;
    }

    public void setUserName(String username) {
        this.username = username;
    }

    public String validate(){
      System.out.println("in bean");
        response = userFacade.validateUser(username, password);

      if (response.equals("MATCH"))          
          return "welcome.xhtml";
      else
          return "login.xhtml";

    }
}
4

1 に答える 1

0

.xhtml ページの上にあるタグの xhtml 宣言と jsf 宣言を指定しましたか?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<h:body>
   your code here....
</h:body>

</html>

web.xml で次のように指定しましたか?

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

マネージドBeanで「faces /」を指定してみてください

if (response.equals("MATCH"))          
      return "faces/welcome.xhtml";
  else
      return "login.xhtml";

.xhtml ログイン ファイルでは、代わりにフォームを使用します。<h:form>

<form>
</form>

faceConfig でナビゲーション ルールを指定してみてください

<navigation-rule>
  <display-name>login.xhtml</display-name>
  <from-view-id>/faces/login.xhtml</from-view-id>
  <navigation-case>
   <from-action>#{userBean.validate}</from-action>
   <from-outcome>welcome.xhtml</from-outcome>
   <to-view-id>/faces/welcome.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>

参照用のリソース、 http://docs.oracle.com/cd/E14545_01/help/org.eclipse.jst.jsf.facelet.doc.user/html/gettingstarted/tutorial/JSF%20Facelets%20Tools%20Tutorial。 html

于 2012-10-09T03:52:17.137 に答える