Giter Site home page Giter Site logo

bolt's Introduction

Bolt

It's a micro web MVC framework write in Java.

Requirements

Java 1.5+

Dependencies

log4j 1.2+

Install

To use Bolt in your web application, you just need to define the follow servlet in the web.xml file:

<servlet>
    <servlet-name>Bolt</servlet-name>
    <servlet-class>br.com.boltframework.Bolt</servlet-class>
    <init-param>
        <param-name>applicationContext</param-name>
        <param-value>app</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Bolt</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

The init parameter called "applicationContext" should be the same value of the "url-pattern" (without '/' and '*').
Currently the framework doesn't work with extension mapping yet (example: *.do).

Usage

controllers

You should annotate the controller with @Controller and define the mappedBy parameter.

@Controller(mappedBy = "welcome")
public class WelcomeController {

}

Actions

You should annotate the action with @Action and define the http method that it can receive.

@Action(methods = HttpMethod.GET)
public Result index(HttpServletRequest request, HttpServletResponse response) {
    return ViewHelper.forwardToDefaultView();
}

An action can response to more of one http method.

@Action(methods = { HttpMethod.GET, HttpMethod.POST })
public Result index(HttpServletRequest request, HttpServletResponse response) {
    return ViewHelper.forwardToDefaultView();
}

Views

By default, views are in WEB-INF/views folder and each jsp file follow the following convertion "controller mapping"/"action name".jsp.
The example below uses the following JSP file: /WEB-INF/views/welcome/index.jsp

@Controller(mappedBy = "welcome")
public class WelcomeController {

    @Action(methods = HttpMethod.GET)
    public Result index(HttpServletRequest request, HttpServletResponse response) {
        return ViewHelper.forwardToDefaultView();
    }

}

Forward and Redirect

To forward or redirect an action or a view you should use the ViewHelper class.

forward the current action to its default view:

ViewHelper.forwardToDefaultView();

forward to another view in some other controller or in the current controller:

ViewHelper.forwardToView(String controller, String view);

redirect the current action to another action in some other controller or in the current controller:

ViewHelper.redirectToAction(HttpServletRequest request, String controller, String action);

forward the current action to another action in some other controller or in the current controller:

ViewHelper.forwardToAction(HttpServletRequest request, String controller, String action); 

Building in your machine

If you want to build it, you'll need to install Gradle.
Then, execute:

gradle build

If you want to see the code into Eclipse, you'll need to generate eclipse project files. Then, execute:

gradle eclipse

Author

Rodrigo Lazoti - [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.