The aim of this project is to provide a simple MVC structure to organize your Servlet applications.
Post class can have index method for showing all post, view for viewing a single post, edit for edit post form, store for saving post by POST request.git clone https://github.com/rezve/kodvel.git
cd kodvel
├── Web Pages
│ ├── WEB-INF
│ │ ├── views # define your views in this folder (JSP files)
│ │ └── web.xml
│ └── resources # static resources (css,js,image, etc)
│
├── Source Packages
│ ├── app
│ │ ├── config # project configuration
│ │ ├── controllers # all the controller classes
│ │ ├── models # all models (Beans)
│ │ └── routes # register your routes here
│ └── Kodvel # system files
└── ...
Step 1:
Let's start by creating a simple JSP view in view/blog folder
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Blog</title>
</head>
<body>
<h1>List of Posts</h1>
</body>
</html>Setp 2:
Now, Create a controller class inside app/controllers folder. This will serve our views.
public class Blog extends Controller{
public void index(HttpServletRequest req, HttpServletResponse res) {
req.setAttribute("posts", posts);
view("blog/posts", req, res);
}
public void create(HttpServletRequest req, HttpServletResponse res) {
view("blog/create", req, res);
}
...
}NOTE: All methods (those are used for handling user request) inside a controller must have this two argument.
We have completed our first controller. Now register it to receive user request.
Step 3: Define a route in app/routes/web.java
public void registerRouter() {
...
Router.get("/blog", new Blog(), "index");
Router.get("/blog/create", new Blog(), "create");
}here we registered our index method for handling all the request for /blog and create method for /blog/create url.
Done! Lets visit http://localhost:8080/kodvel/blog
You will see your views in the browser.
List of Posts
So here is the flow:
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details