JSF简单实例及无法正常访问的解决方法(404和The markup in the document preceding the root element must be well-formed. )
2013-12-05 11:01
796 查看
一、HTTP Status 404 - /JSFLoginDemo/userLogin.faces
去除如下红色配置即可正常访问:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!--
此处所有代码都是在使用MyEclipse的Guide过程中产生的配置,所以要根据实际情况进行配置的设置。
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<!-- 所有的servlet的name为"FacesServlet"的页面都以*.faces访问 -->
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这样通过“http://localhost:8080/JSFLoginDemo/userLogin.faces”访问到登录页面了。
注意,这里配置“Faces Servlet”的“url-pattern”为“*.faces”,所以访问包含JSF的JSP页面时,应该是“页面名称.faces”。
也就是说,直接访问/userLogin.jsp,若/userLogin.jsp中没有JSF代码一切正常,否则会报
Cannot find FacesContext 错误.。
二、error Traced[line: 1] The markup in the document preceding the root element must be well-formed.
因为所写的jsp文件不符合xhtml规则,命名空间不要在使用@包含:
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@page contentType="text/html;charset=GB2312"%>
需要将对应的内容转换成Xhtml格式:
<?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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xml:lang="en"
lang="en">
<head>
<title>Index</title>
</head>
<body>
<f:view>
.......//此处省略
</f:view>
</body>
</html>
三、org.apache.jasper.JasperException: /index.jsp(15,33) #{...} is not allowed in template text.
这样,页面就能正常运行了。
去除如下红色配置即可正常访问:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!--
此处所有代码都是在使用MyEclipse的Guide过程中产生的配置,所以要根据实际情况进行配置的设置。
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<!-- 所有的servlet的name为"FacesServlet"的页面都以*.faces访问 -->
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这样通过“http://localhost:8080/JSFLoginDemo/userLogin.faces”访问到登录页面了。
注意,这里配置“Faces Servlet”的“url-pattern”为“*.faces”,所以访问包含JSF的JSP页面时,应该是“页面名称.faces”。
也就是说,直接访问/userLogin.jsp,若/userLogin.jsp中没有JSF代码一切正常,否则会报
Cannot find FacesContext 错误.。
二、error Traced[line: 1] The markup in the document preceding the root element must be well-formed.
因为所写的jsp文件不符合xhtml规则,命名空间不要在使用@包含:
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@page contentType="text/html;charset=GB2312"%>
需要将对应的内容转换成Xhtml格式:
<?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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xml:lang="en"
lang="en">
<head>
<title>Index</title>
</head>
<body>
<f:view>
.......//此处省略
</f:view>
</body>
</html>
三、org.apache.jasper.JasperException: /index.jsp(15,33) #{...} is not allowed in template text.
这样,页面就能正常运行了。
相关文章推荐
- spring配置文件报错:the markup in the document preceding the root element must be well-formed
- 编写xml文件时,The markup in the document preceding the root element must be well-formed.等bug
- 解决The markup in the document following the root element must be well-formed.
- The markup in the document preceding the root element must be well-formed
- the markup in the document preceding the root element must be well-formed
- The markup in the document following the root element must be well-formed
- The markup in the document following the root element must be well-formed. Quartz.xml .......
- org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-fo
- org.xml.sax.SAXParseException: The markup in the document following the root element must be well-fo
- Caused by: org.xml.sax.SAXParseException; systemId: file:/home/hadoop/hive-0.12.0/conf/hive-site.xml; lineNumber: 5; columnNumber: 2; The markup in the document following the root element must be well
- The markup in the document following the root element must be well-formed.
- Soap: The root element is required in a well-formed document.
- Guestinfo.hbm(1)The markup declarations contained or pointed to by the document type declaration must be well-formed
- The content of elements must consist of well-formed character data or markup解决方法
- Document root element "beans", must match DOCTYPE root "null"分析及解决方法
- JSF遭遇XML解析错误The content of elements must consist of well-formed character data or markup
- sharepoint 2010 列表的数据表视图无法使用 the list cannot be displayed in datasheet view 解决方法
- [置顶] JAVA中 错误代码是 the public type must be defined in its own file 解决方法 android开发 java编程
- “The public type XYZ must be defined in its own file”解决方法
- Document root element "beans", must match DOCTYPE root "null". 解决方法