JSF 2.0 导航系统不使用 .jsp 扩展名
JSF 2.0 Navigation system Not Working with .jsp extension
我已经将 JSF2.0 用于自动导航系统。我有一个简单的登录页面,当我单击登录按钮时,相应 Bean class 的方法已被调用,但它不会当我将扩展名从 .jsp 更改为 xhtml 时导航到 home.jsp 页面然后它工作。 .jsp 扩展名有什么问题。
LoginBean.java
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String uname;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String loginProject() {
System.out.println("hello i am called ");
System.out.println(uname);
System.out.println(password);
return "home";
}
}
===============
login.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Colonial Inn</title>
</h:head>
<h:body>
<div align="center">
<h:form id="loginForm">
<p:growl id="msg" showDetail="true" life="3000" />
<p:panel header="Login" style="width: 360px,margin-left:200px;">
<h:panelGrid id="loginPanel" columns="2">
<h:outputText value="Username" />
<p:inputText id="username" value="#{loginBean.uname}"
required="true">
</p:inputText>
<p:spacer></p:spacer>
<p:message for="username"></p:message>
<h:outputText value="Password" />
<p:password id="password" value="#{loginBean.password}"
feedback="false" required="true"></p:password>
<p:spacer></p:spacer>
<p:message for="password"></p:message>
<p:spacer></p:spacer>
<h:commandButton action="#{loginBean.loginProject}" value="Login"></h:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</div>
</h:body>
</html>
===================
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>NewCalonialinn</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
================
home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to home page </h1>
</body>
</html>
What is the problem with .jsp extension.
从 JSF 2.0 开始是 deprecated。
坚持使用 .xhtml 扩展名。
另请参阅:
- Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
我已经将 JSF2.0 用于自动导航系统。我有一个简单的登录页面,当我单击登录按钮时,相应 Bean class 的方法已被调用,但它不会当我将扩展名从 .jsp 更改为 xhtml 时导航到 home.jsp 页面然后它工作。 .jsp 扩展名有什么问题。
LoginBean.java
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String uname;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String loginProject() {
System.out.println("hello i am called ");
System.out.println(uname);
System.out.println(password);
return "home";
}
}
===============
login.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Colonial Inn</title>
</h:head>
<h:body>
<div align="center">
<h:form id="loginForm">
<p:growl id="msg" showDetail="true" life="3000" />
<p:panel header="Login" style="width: 360px,margin-left:200px;">
<h:panelGrid id="loginPanel" columns="2">
<h:outputText value="Username" />
<p:inputText id="username" value="#{loginBean.uname}"
required="true">
</p:inputText>
<p:spacer></p:spacer>
<p:message for="username"></p:message>
<h:outputText value="Password" />
<p:password id="password" value="#{loginBean.password}"
feedback="false" required="true"></p:password>
<p:spacer></p:spacer>
<p:message for="password"></p:message>
<p:spacer></p:spacer>
<h:commandButton action="#{loginBean.loginProject}" value="Login"></h:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</div>
</h:body>
</html>
===================
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>NewCalonialinn</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
================
home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to home page </h1>
</body>
</html>
What is the problem with .jsp extension.
从 JSF 2.0 开始是 deprecated。
坚持使用 .xhtml 扩展名。
另请参阅:
- Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?