未使用shiro呈现JSF组件
为了学习如何使用ApacheShiro,我正在使用来自的BalusC指南。我在Windows7x64中使用JSF2.2、Neatbeans7.4、Shiro1.2.2、JavaEE7和Glassfish 4。我的问题是,当我通过Netbeans尝试查看选项或尝试使用url直接访问页面时,我的login.xhtml页面上的组件不会呈现,但当我运行项目并自动加载它时,它们会工作(这是我的欢迎页面)。通常显示纯文本 login.xhtml页面:未使用shiro呈现JSF组件,jsf,netbeans,glassfish,shiro,Jsf,Netbeans,Glassfish,Shiro,为了学习如何使用ApacheShiro,我正在使用来自的BalusC指南。我在Windows7x64中使用JSF2.2、Neatbeans7.4、Shiro1.2.2、JavaEE7和Glassfish 4。我的问题是,当我通过Netbeans尝试查看选项或尝试使用url直接访问页面时,我的login.xhtml页面上的组件不会呈现,但当我运行项目并自动加载它时,它们会工作(这是我的欢迎页面)。通常显示纯文本 login.xhtml页面: <?xml version='1.0' encod
<?xml version='1.0' encoding='UTF-8' ?>
<!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:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h2>Login</h2>
<h:form id="login">
<h:panelGrid columns="3">
Plain Text
<h:outputLabel for="username" value="Username:" />
<h:inputText id="username" value="#{login.username}" required="true">
<f:ajax event="blur" render="m_username" />
</h:inputText>
<h:message id="m_username" for="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret id="password" value="#{login.password}" required="true">
<f:ajax event="blur" render="m_password" />
</h:inputSecret>
<h:message id="m_password" for="password" />
<h:outputLabel for="rememberMe" value="Remember Me:" />
<h:selectBooleanCheckbox id="rememberMe" value="#{login.remember}" />
<h:commandButton value="Login" action="#{login.submit}" >
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:messages globalOnly="true" layout="table" />
</h:panelGrid>
</h:form>
</h:body>
我也得到了这个错误
A managed bean with a public field (“HOME_URL”) should not declares any scope other than @Dependent
即使它似乎有效
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
我收到的警告/错误(glassgish):
我有两个网页:
/login.xhtml
/app/index.xhtml
有什么建议吗?(我是noob,所以请温柔一点!:P)签出这一行日志
SEVERE: Unable to load annotated class: model.LoginBean, reason: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Shiro依赖slf4j进行日志记录,而您缺少slf4j依赖项。您可以在此处下载JAR:
我建议您将以下JAR添加到类路径:
- slf4j-api-1.7.5.jar
- slf4j-simple-1.7.5.jar
- slf4j-log4j12-1.7.5.jar
- slf4j-jcl-1.7.5.jar
- slf4j-jdk14-1.7.5.jar
- logback-classic-1.0.13.jar(需要logback-core-1.0.13.jar)
有关slf4j的更多详细信息,请参阅手册:我今天遇到了完全相同的问题。找到BalusC在不同主题中的答案(或至少一个提示) 在我的例子中,页面与FacesServlet的url模式不匹配。我所要做的就是改变web.xml中的模式:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Facesservlet
*.xhtml
公共静态最终字符串HOME\u URL=“app/index.xhtml”
这就是错误所在,我想您现在应该知道,您应该更喜欢私有变量声明而不是公共变量声明。所以用这个代替。
干杯
私有静态最终字符串HOME\u URL=“app/index.xhtml” 对不起,这完全是胡说八道。
/login.xhtml
/app/index.xhtml
SEVERE: Unable to load annotated class: model.LoginBean, reason: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>