I am trying to create a web page using JavaEE
I have created a new web project in netbeans. It has generated a typical html page:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div></div>
</body>
</html>
But lets say I want to print information from the server. I created class
@Stateless
@Path("/")
public class NewClass {
public String name = "MyName";
@GET
public String getName(){
return this.name;
}
}
with route "/" for testing. I want to print the name
variable inside the page. I have tried using
<div>#{NewClass.getName()}</div>
in html but it just printed "#{NewClass.getName()}"
What is the right way to do it? Is ( using .html
) the only way to do it using ajax?
/////
I have tried generating JSP
<?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>
"#{NewClass.getName()}"
</h:body>
</html>
But it just prints ""
I cannot find any good resource for this.