- Jakarta EE Cookbook
- Elder Moraes
- 153字
- 2021-06-24 16:12:41
How to do it...
You need to perform the following steps to try this recipe:
- Start by creating a root for your JAX-RS endpoints:
@ApplicationPath("webresources")
public class AppConfig extends Application{
}
- Create a User class (this will be your Model):
public class User {
private String name;
private String email;
public User(String name, String email) {
this.name = name;
this.email = email;
}
//DON'T FORGET THE GETTERS AND SETTERS
//THIS RECIPE WON'T WORK WITHOUT THEM
}
- Now, create a session bean, which will be injected later in your Controller:
@Stateless
public class UserBean {
public User getUser(){
return new User("Elder", "elder@eldermoraes.com");
}
}
- Then, create the Controller:
@Controller
@Path("userController")
public class UserController {
@Inject
Models models;
@Inject
UserBean userBean;
@GET
public String user(){
models.put("user", userBean.getUser());
return "/user.jsp";
}
}
- And finally, create the web page (the View):
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>User MVC</title>
</head>
<body>
<h1>${user.name}/${user.email}</h1>
</body>
- Run it on a Jakarta EE 8 server and access this URL:
http://localhost:8080/ch01-mvc/webresources/userController
推薦閱讀
- Vue.js 2 and Bootstrap 4 Web Development
- HBase從入門到實戰
- Julia機器學習核心編程:人人可用的高性能科學計算
- Learn Swift by Building Applications
- Hands-On Swift 5 Microservices Development
- RabbitMQ Essentials
- 從零開始學Linux編程
- Node.js開發指南
- OpenCV 3 Blueprints
- Python Projects for Kids
- Java高級程序設計
- UI動效設計從入門到精通
- Responsive Web Design with jQuery
- 用Go語言自制編譯器
- Web前端開發全程實戰:HTML5+CSS3+JavaScript+jQuery+Bootstrap