Primefaces web.xml的问题

Primefaces web.xml的问题,primefaces,tomcat7,web.xml,jdbcrealm,Primefaces,Tomcat7,Web.xml,Jdbcrealm,首先,我想为我的英语不好道歉。好的,我有个问题。我正在构建使用jdbcrealm和web.xml实现安全性的应用程序。登录是通过web表单完成的。应用程序在ApacheTomcat7上运行,我使用的是PrimeFaces4.0。在web.xml中,我定义了一些角色和一些安全约束。当我登录到应用程序httpservlet request.login(用户名、密码)做得很好,并且request.isUserInrole(“角色”)也做得很好,Faces.getExternalContext.redi

首先,我想为我的英语不好道歉。好的,我有个问题。我正在构建使用jdbcrealm和web.xml实现安全性的应用程序。登录是通过web表单完成的。应用程序在ApacheTomcat7上运行,我使用的是PrimeFaces4.0。在web.xml中,我定义了一些角色和一些安全约束。当我登录到应用程序httpservlet request.login(用户名、密码)做得很好,并且request.isUserInrole(“角色”)也做得很好,Faces.getExternalContext.redirect将页面重定向到应用了安全约束的正确文件夹,在浏览器中我看到了正确的URL…但页面是空白的!!!如果我检查页面来源,我会看到登录页面的页面来源……我会在下面放一些屏幕截图。请帮帮我…我正在试着解决这个问题两个星期了

/*

*/ 这是web.xml

    <param-name>primefaces.THEME</param-name>

    <param-value>afterdark</param-value>

</context-param>

<servlet>

    <servlet-name>Faces Servlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping> 

    <servlet-name>Faces Servlet</servlet-name>

   <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<security-role>
    <description>Administrator A</description>
    <role-name>1</role-name>
</security-role>
 <security-constraint>
    <display-name>Administrator A</display-name>
    <web-resource-collection>
        <web-resource-name>Administratorske datoteke</web-resource-name>
        <description/>
        <url-pattern>/a1/*</url-pattern> --> 
        <http-method>GET</http-method>
        <http-method>POST</http-method>        
    </web-resource-collection>
    <auth-constraint>
        <description>Administrator A</description>
        <role-name>1</role-name>
      </auth-constraint>
</security-constraint>


    <login-config>

    <auth-method>FORM</auth-method>
    <realm-name>JDBCRealm</realm-name>
    <form-login-config>
        <form-login-page>/prijava.xhtml</form-login-page>
        <form-error-page>/pogreska.xhtml</form-error-page>
    </form-login-config>
</login-config>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>prijava.xhtml</welcome-file>
</welcome-file-list>

这是角色为“1”的用户登录时在我的浏览器中的url。在此之前,本地主机和端口…ERMP是应用程序的neme…

“ERMP/a1/pocetna_a1.xhtml”

这是一个空白页面,页面来源为登录页面

我希望这个问题可以理解。 当在web.xml中注释web资源时,一切正常
请帮忙!!谢谢

当您想使用tomcat的内置()身份验证和授权时,有几件事您应该注意

首先,您的登录表单需要如下所示:

<form action="j_security_check" method="post">
    <input type="text" name="j_username" placeholder="Login"/>
    <input type="password" name="j_password" placeholder="Password"/>
    <input type="submit" value="Sign In" />
</form>

可以使用primefaces组件来保留布局。在这种情况下,您需要执行一些“javascripting”来定义JSFh:form组件重新编写的表单的操作。 ...


jQuery(“#表单”).submit(函数(){
jQuery(this).attr(“操作”、“j_安全检查”);
jQuery(loginVar.jqId).attr(“名称”、“j_用户名”);
....
});

第二个细节是,您不需要担心登录控制器中描述的登录部分。一旦您将j_用户名和j_密码发送给j_安全检查,一切都会正常运行。

谢谢!我设法进入了所需的页面,这是一个改进,但我只能对一个用户这样做……如果我为角色为“1”的用户定义欢迎页面,我可以看到该页面,但角色为“2”的用户看不到该页面……您知道如何在web.xml中定义多个欢迎页面吗?
    FacesMessage poruka = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletRequest zahtjev = (HttpServletRequest) fc.getExternalContext().getRequest();
    try {
        String pocetna_stranica;            
        zahtjev.login(k_ime, zaporka);
        HttpSession sesija = zahtjev.getSession();
        if (!sesija.isNew()) {
            sesija.invalidate();
            sesija = zahtjev.getSession();                                
        }
        if (zahtjev.isUserInRole("1")) {
            sesija.setAttribute("trenutni_korisnik",k_ime);
            pocetna_stranica = "/a1/pocetna_a1.xhtml";
            poruka = new FacesMessage(FacesMessage.SEVERITY_INFO, "Dobro došao", k_ime);
            try {
                fc.getExternalContext().getFlash().setKeepMessages(true);
                fc.getExternalContext().redirect(zahtjev.getContextPath()+pocetna_stranica);

            }
            catch (IOException ex) {
                fc.addMessage(null, new FacesMessage("UPOZORENJE!", "Pogreška u izvođenju programa. Nije moguće preusmjeriti stranicu."));
            }
        } 
        else if (zahtjev.isUserInRole("2")) {
<form action="j_security_check" method="post">
    <input type="text" name="j_username" placeholder="Login"/>
    <input type="password" name="j_password" placeholder="Password"/>
    <input type="submit" value="Sign In" />
</form>
<script>
jQuery("#form").submit(function() {
  jQuery(this).attr("action", "j_security_check");
  jQuery(loginVar.jqId).attr("name", "j_username");
  ....
});
</script>