【发布时间】:2022-01-10 07:07:04
【问题描述】:
我也在使用 jboss 服务器和 primefaces。我想为我的登录页面使用谷歌验证码。起初没关系,验证码出现了,但我希望验证码公钥和私钥存储在属性文件中。我做了这样的配置:
web.xml
<listener>
<listener-class>
com.putra.web.CaptchaConfig
</listener-class>
</listener>
<context-param>
<param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name> <!-- SECRET KEY -->
<param-value>${PRIVATE_CAPTCHA_KEY}</param-value>
</context-param>
<context-param>
<param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name> <!-- PUBLIC KEY -->
<param-value>${PUBLIC_CAPTCHA_KEY}</param-value>
</context-param>
CaptchaConfig.java
public class CaptchaConfig implements ServletContextListener {
private static final Logger LOG = LoggerFactory.getLogger(CaptchaConfig.class);
@Override
public void contextDestroyed(final ServletContextEvent event) {
}
@Override
public void contextInitialized(final ServletContextEvent event) {
final String props = "/captcha.properties";
final Properties propsFromFile = new Properties();
try {
LOG.info("### Load captcha config file ###");
propsFromFile.load(getClass().getResourceAsStream(props));
} catch (final IOException e) {
LOG.info("### Error load captcha config file ###");
}
for (String prop : propsFromFile.stringPropertyNames()) {
LOG.info("### Properties Name : {} ###", prop);
LOG.info("### Properties Value : {} ###", propsFromFile.getProperty(prop));
System.setProperty(prop, propsFromFile.getProperty(prop));
}
}
}
验证码属性
PRIVATE_CAPTCHA_KEY=6Lc2QvgdAAAAAC9rcBbP2RfvVXPf2_xxxxxxxxxx
PUBLIC_CAPTCHA_KEY=6Lc2QvgdAAAAAH2Psp5-ILyWLenJJ4xxxxxxxxxx
我在运行项目时没有出错,但问题是验证码没有显示出来。怎么了?
【问题讨论】:
-
检查
web.xml是否在其标头中包含正确的版本(根据Java Servlet 版本正在使用您的服务器)。您可以发布您的web.xml标头和服务器版本吗?
标签: jakarta-ee primefaces jboss web.xml