Skip to content

Java

import java.util.*;

public class test{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        System.out.println("What is your favorite Web Application Language?");
        String answer = scanner.nextLine();
        System.out.println("Your answer was: " + answer);
    }
}

After compiling the source code, test.class is written to our JAR directory. In order to package our class as a JAR file, we will need to create a manifest file. This is easily accomplished by creating the JAR/META-INF directory and adding our test class to the MANIFEST.MF file as shown below.

# compile java source code
$ javac -source 1.8 -target 1.8 test.java

# create manifest file
$ mkdir META-INF

$ echo "Main-Class: test" > META-INF/MANIFEST.MF

# create our JAR file
$ jar cmvf META-INF/MANIFEST.MF test.jar test.class

# test our example class
$ java -jar test.jar

Java Web

Some Java applications use Servlet Mappings to control how the application handles HTTP requests. In Java web applications, there can be multiple entries in a web.xml file, each route is made up of two entries: one entry to define a servlet and a second entry to map a URL to a servlet.

<!-- SubscriptionHandler-->
<servlet id="SubscriptionHandler">
  <servlet-name>SubscriptionHandler</servlet-name>
  <servlet-class>org.opencrx.kernel.workflow.servlet.SubscriptionHandlerServlet</servlet-class>
    </servlet>
...
<servlet-mapping>
  <servlet-name>SubscriptionHandler</servlet-name>
    <url-pattern>/SubscriptionHandler/*</url-pattern>
</servlet-mapping>

An example os Express.js routing

var express = require('express');
var router = express.Router();
...

router.get('/login', function(req, res, next) {
  res.render('login', { title: 'Login' });
});

A variant of this approach is routing by annotation or attribute. The Spring MVC2 framework for Java and the Flask framework for Python, among others, use this approach.

@GetMapping({"/admin/users"})
public String getUsersPage(HttpServletRequest req, Model model, HttpServletResponse res) {
...