java - jsf中不能调用Bean?
问题描述
我正在使用 jave 的 JSF 框架。我有一个问题。当我使用 url-pattern 是 /faces/* 时,我可以调用 bean。但是当我将 url-pattern 更改为 *.xhtml 时,我不能。我必须如何解决这个问题。
我的豆子
@ManagedBean
@Named(value = "employerBean")
@SessionScoped
public class EmployerBean implements Serializable {
// private final static EmployerService epmservice = new EmployerService();
/**
* Creates a new instance of EmployerBean
*/
public EmployerBean() {
}
public List<String> getCompanies() {
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
return messages;
}
}
web.xml
<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>/faces/*</url-pattern>-->
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
解决方案
推荐阅读
- flutter - Flutter 制作掷骰子动画
- sql - 计算百分比的正确方法?
- javascript - 找不到节点的导出名称(ButtonRadioGroupDirective 类 ...)
- android - Android Studio 版本控制 (VCS) - 如何忽略 Android Studio 3.6.x 中的文件?
- javascript - Firestore 将身份验证添加到请求
- sql-server - In Azure Logic Apps ARM template, what are the possible values for the AuthType property for a SQL Server connector using On-Premise Data Gateway?
- javascript - 在项目之间共享 JS 代码的另一种选择,然后是 yarn 工作区(monorepo)或公共/私有 npm 包
- asp.net-core - Swagger 对具有参数的控制器操作不显示任何参数
- java - 如何找到有效子集和最佳有效子集?
- firebase - 如何在不指定的情况下在 Firebase 上获取子集合?