尝试在中创建第一个hello world Java web应用程序
NetBeans
GlassFish 5
在本地主机上运行的服务器。当我在中运行应用程序时
NetBeans 10
http://localhost:8080/intro-to-jsf-nb10/
有错误的页面
HTTP Status 404 - Not Found
我早就料到了
NB
将在中的某个位置部署项目文件
GlassFish
文件夹,但我找不到
index.xhtml
如果我导航到
GF5\glassfish\domains\domain1\docroot
文件夹我看到默认的GlassFish网页索引.xtml,但不是我的。
如何解决这个问题?
WelcomePageBean
Java类:
package com.samples.linkedin.jsf.page;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named("welcomePageBean")
@RequestScoped
public class WelcomePageBean {
private String welcomeUserName;
private String completedGreeting;
/**
* @return the welcomeUserName
*/
public String getWelcomeUserName() {
return welcomeUserName;
}
/**
* @param welcomeUserName the welcomeUserName to set
*/
public void setWelcomeUserName(String welcomeUserName) {
this.welcomeUserName = welcomeUserName;
}
/**
* @return the completedGreeting
*/
public String getCompletedGreeting() {
return completedGreeting;
}
/**
* @param completedGreeting the completedGreeting to set
*/
public void setCompletedGreeting(String completedGreeting) {
this.completedGreeting = completedGreeting;
}
public void sayHello()
{
completedGreeting = "Hello, "+welcomeUserName;
}
}
index.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://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel for="inputTextBox" value="Enter a name here" />
<h:inputText value="#{welcomePageBean.welcomeUserName}" id="inputTextBox"></h:inputText>
<h:commandButton value ="Say Hello" action="#{welcomePageBean.sayHello}"/>
<h:outputText value="#{welcomePageBean.completedGreeting}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>