- Singleton class
- Session
- Authentification/Authorization with many profiles
- Return Json (via modelView)
- Rest API (direct returning object)
- File upload, input array
-
app.xml
external configuration file -
framework.sh
manager: build, launch and hot reload - 🎉 Database integration: see 👉 Unidao here
- 🎉 Mini Scaffolding integration: generate CRUD 👉 See here
- Error page (404, 500...)
- Log system
- Full Documentation
... and more
Requirements | Version |
---|---|
JDK ☕️ | equal or upper 17 |
Tomcat 🐱 | equal or upper 10 |
Gson library 📚 | 2.10 (provided ✅) |
OS 💻 | can run bash script |
There is 3 versions, get the last released from the releases page
- Production version: contains the framework with
framework.sh
manager - Manual version: contains only
framework.jar
. See manual installation below - Demo version: production version with a demo project
- Open
conf.env
file and set all: jdk, tomcat, information about your project like where the project will be created
If it is not in your file get it from here and change - Then, give permissions for
framework.sh
the script that will help you to manage the framework
sudo chmod +x framework.sh
- Finally,
init
your repository for a weby project
./framework.sh --init
- To run your project you can use the script
framework.sh
, makeframework.sh --help
to see all options
./framework.sh --run
The script will compile your project and run it in tomcat with
auto reload
feature enabled, for*.xml
or any configurations changed you might sometimes need to restart tomcat⚠️
After downloading the jar file, you can add it to your lib project and use it as a dependency (make Gson in your dependency too).
Create a file app.xml
in your project and copy the basic configuration below.
<?xml version="1.0" encoding="utf-8" ?>
<app>
<config id="auth">
<session name="profile" />
<profiles>
<profile name="AUTH_PROFILE_ADMIN" value="admin" />
<profile name="AUTH_PROFILE_USER" value="user" />
</profiles>
<redirections>
<redirect name="AUTH_REDIRECT_LOGIN" value="/" />
<redirect name="AUTH_REDIRECT_LOGOUT" value="/login" />
</redirections>
</config>
</app>
You must set PACKAGE_ROOT and CONFIG_FILE parameters
...
<!-- This is the main servlet of the framework -->
<servlet>
<servlet-name>FrontServlet</servlet-name>
<servlet-class>etu2024.framework.servlet.FrontServlet</servlet-class>
<init-param>
<!-- The root package of your project -->
<param-name>PACKAGE_ROOT</param-name>
<param-value>.../popo/src/main/java/</param-value>
</init-param>
<init-param>
<!-- The path to the configuration file -->
<param-name>CONFIG_FILE</param-name>
<param-value>.../popo/src/app.xml</param-value>
</init-param>
</servlet>
<!-- All the requests are processed by FrontServlet -->
<servlet-mapping>
<servlet-name>FrontServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
...
Let's learn by examples, it is the best (and fastest) way to learn. ℹ️
import etu2024.framework.annotation.Auth;
import etu2024.framework.core.ModelView;
...
@Url(url = "/") // The url where the controller will be called
public ModelView index() {
ModelView modelView = new ModelView(); // A class to manage the view
modelView.setView("home.jsp"); // The page to render
return modelView;
}
...
Example of rest controller using Unidao
@Url(url="/regions", method=Mapping.POST)
@RestAPI
public Region save(@JsonObject Region region) throws DaoException {
Service service = database.connect();
Region region = region.save(service);
service.endConnection();
return region;
}
...
// The class where all process will be done
ModelView modelView = new ModelView();
// Add a variable to the view
modelView.addItem("name", "Weby");
// The page to render
modelView.setView("home.jsp");
...
Attributes and parameters are filled automatically
public class Customer()
private String name;
...
public ModelView getCustomer(String id) {
ModelView modelView = new ModelView();
// Access directly to the variable name and id
modelView.setView("home.jsp");
return modelView;
}
...
...
ModelView modelView = new ModelView();
return modelView.redirect("/home");
...