- 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
推薦閱讀
- iOS Game Programming Cookbook
- C++ Primer習(xí)題集(第5版)
- SOA實踐
- 網(wǎng)頁設(shè)計與制作教程(HTML+CSS+JavaScript)(第2版)
- Kotlin Standard Library Cookbook
- Hands-On Enterprise Automation with Python.
- 深入分布式緩存:從原理到實踐
- Android群英傳
- 軟件工程基礎(chǔ)與實訓(xùn)教程
- Webpack實戰(zhàn):入門、進階與調(diào)優(yōu)(第2版)
- Python網(wǎng)絡(luò)爬蟲技術(shù)與應(yīng)用
- OpenCV 3計算機視覺:Python語言實現(xiàn)(原書第2版)
- JavaScript編程精解(原書第2版)
- SAP Web Dynpro for ABAP開發(fā)技術(shù)詳解:基礎(chǔ)應(yīng)用
- Android智能手機APP界面設(shè)計實戰(zhàn)教程