mmu*_*lva 14 jsf netbeans glassfish java-ee
我正在使用Netbeans和Glassfish来学习Java EE firstcup教程.
当我执行JSF Web层时,我已被指示编码,浏览器获得在.xhtml文件中编码的相同JSF标记,并且标记不会呈现为HTML标记.我通过在浏览器中使用视图源代码来了解这一点.
例如,对于此代码:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Page title here</title>
</h:head>
<h:body>
<h2>
<h:outputText value="#{bundle.WelcomeMessage}" />
</h2>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
浏览器应该是这样的:
<html ...>
<head>
<title>Page title here</title>
</head>
<body>
<h2>
the welcome message goes here
</h2>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
对?
好吧,我的浏览器正在获取jsf代码(上面的第一段代码)而不是html代码(上面的第二段代码).
这似乎是netbeans或glassfish中的配置问题,但不知道是什么.有任何想法吗?
这是我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.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>/firstcup/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>greetings.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)
这是我的faces-config.xml文件:
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<resource-bundle>
<base-name>firstcup.web.WebMessages</base-name>
<var>bundle</var>
</resource-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/greetings.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/response.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Run Code Online (Sandbox Code Playgroud)
此外:
Bal*_*usC 20
如果没有解析JSF标记,那么它只是意味着请求尚未通过FacesServlet
.那个servlet是负责所有JSF东西的人.您需要验证,如果使用的请求URL匹配url-pattern
的FacesServlet
.请注意,它区分大小写.
但是,如果直接在IDE的内置浏览器中打开文件,也可能会发生这种情况.你不应该这样做.您需要在内置浏览器或外部浏览器(例如MSIE/Firefox)的地址栏中自己指定正确的URL.
更新:还有一件事,您是否在<html xmlns>
attribtue中声明了JSF HTML taglib ?您在代码段中省略了它.
应该是这样的
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
Run Code Online (Sandbox Code Playgroud)
小智 9
web.xml中的以下代码
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
而不是faces/*
解决了我的非渲染jsf标签的问题.
注意:*.html
导致stackoverflow
已解决:将web.xml中的welcome-文件更改为以下内容解决了问题:
<welcome-file-list>
<welcome-file>firstcup/greetings.xhtml</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20396 次 |
最近记录: |