虽然我已经浏览了these four SO questions,但在我在servlet中创建的第一个JSF页面被调用时,我仍然只得到一个空白页面。它通过IntelliJ IDEA部署在Tomcat 7服务器上。在错误日志级别“全部”,我没有收到任何错误消息。浏览器中的源代码保持完全为空。好像FacesServlet没有被调用,但IMO它不能归因于url-mapping,对我来说似乎没关系! 还有其他可能性,也可以查看错误日志吗?
的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>incomingURLs</param-name>
<param-value>http://localhost:8080,http://localhost:63342,https://localhost:63342</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Diagapp</servlet-name>
<servlet-class>com.brainsee.diagapp.DispatcherServlet</servlet-class>
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>Diagapp</servlet-name>
<url-pattern>/diagapp</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Logoff</servlet-name>
<servlet-class>com.brainsee.diagapp.Logoff</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Logoff</servlet-name>
<url-pattern>/logoff</url-pattern>
</servlet-mapping>
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.brainsee.diagapp.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/diagapp/admin</url-pattern>
</filter-mapping>
<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>
</web-app>
diagnosesedit.xhtml:
<!DOCTYPE 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>Diagnoseeditor</title>
</h:head>
<h:body>
<h3>Diagnosen</h3>
<h:form rendered="#{not empty diagnosisBean.list}">
<h:dataTable value="#{diagnosisBean.list}" var="diagnosis">
<h:column><f:facet name="header">ID</f:facet>#{diagnosis.id}</h:column>
<h:column><f:facet name="header">Text</f:facet>#{diagnosis.text}</h:column>
<h:column><f:facet name="header">Alternativname</f:facet>#{diagnosis.altname}</h:column>
<h:column><f:facet name="header">2. Alternativname</f:facet>#{diagnosis.altname2}</h:column>
<h:column><f:facet name="header">ICD-10</f:facet>#{diagnosis.icd10}</h:column>
<h:column><f:facet name="header">Alpha-ID</f:facet>#{diagnosis.alphaid}</h:column>
<h:column><h:commandButton value="edit" action="#{diagnosisBean.edit(diagnosis)}" /></h:column>
<h:column><h:commandButton value="delete" action="#{diagnosisBean.delete(diagnosis)}" /></h:column>
</h:dataTable>
</h:form>
<h:panelGroup rendered="#{empty diagnosisBean.list}">
<p>Table is empty! Please add new diagnoses.</p>
</h:panelGroup>
<h:panelGroup rendered="#{!diagnosisBean.edited}">
<h3>Add diagnosis</h3>
<h:form>
<p>Value: <h:inputText value="#{diagnosisBean.diagnosis.value}" /></p>
<p><h:commandButton value="add" action="#{diagnosisBean.add}" /></p>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{diagnosisBean.edited}">
<h3>Edit diagnosis #{diagnosisBean.diagnosis.id}</h3>
<h:form>
<p>Value: <h:inputText value="#{diagnosisBean.diagnosis.value}" /></p>
<p><h:commandButton value="save" action="#{diagnosisBean.save}" /></p>
</h:form>
</h:panelGroup>
</h:body>
</html>
只用
在我的DispatcherServlet中调用它response.sendRedirect("admin/diagnosesedit.xhtml");
来自同一目录中的jsp文件。
WEB-INF / faces-config.xml中:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" 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-facesconfig_2_2.xsd">
<managed-bean>
<managed-bean-name>diagnosisBean</managed-bean-name>
<managed-bean-class>com.brainsee.diagapp.beans.DiagnosisBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
还有DiagnosisBean:
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.List;
@ManagedBean
@ViewScoped
public class DiagnosisBean implements Serializable {
private List<Diagnosis> list;
private Diagnosis diagnosis = new Diagnosis();
private boolean edited;
@PostConstruct
public void init() {
list = DiagnosisDAO.getAll();
}
public void add() {
DiagnosisDAO.insert(diagnosis);
diagnosis = new Diagnosis();
}
public void edit(Diagnosis diagnosis) {
this.diagnosis = diagnosis;
edited = true;
}
public void save() {
DiagnosisDAO.update(diagnosis);
diagnosis = new Diagnosis();
edited = false;
}
public void delete(Diagnosis diagnosis) {
DiagnosisDAO.delete(diagnosis);
}
public List<Diagnosis> getList() {
return list;
}
public Diagnosis getDiagnosis() {
return diagnosis;
}
public boolean isEdited() {
return edited;
}
}
在我的依赖项中,Mojarra-1.2和javax.faces:javax-faces-api:2.2包含在“提供”范围内(将其更改为“compile”不会改变任何内容)。
答案 0 :(得分:0)
.... ARRRRGH只是查看了great JSF wiki并看到我使用的是Servlet 3.0功能,但将过时的Mojarra-1.2作为库。更新了库和voilà,它可以工作。所以RTFM:)