Simple Servlet example without eclipse

Simple servlet example – how to create servlet without eclipse

These days we are all surrounded by heavy frameworks that make life easier for us. Like maven, spring and hibernate and more. But how can we create a simple servlet website without the need of all those.

The main idea of servlet lies around very simple and intuitive files and structures. Knowing those only is good enough to built a good web app and that is what I will be showing here.

The main parts of the java web app are the following.

1. The Servlet – the java class that is handling the POST and GET http verbs
2. the deployment descriptor – web.xml. File telling how the webapp should be interacted like the url pattern
3. Servlet jar file – This is the jar handling the magic of interaction with the web for the servlet.

Structure of the webapp

Simple Hello world using x86 (32bit) assembly language using function

here is some hello world function that would just add 10 to whatever number it is given

#Simple adder function in assebmly - just adds 10 the called number 
.code32 #if running the code on 64 bit machine
.section .data
.section .text

.globl _start
_start: #entry point

    #Assign the number to be modified here
    push $9 # using immediate access mode just assign number 9
    call adder10 #call the function adder10 here - basically assign a memory address name

    mov %eax, %ebx #pass the return value to ebx since return value sits on eax
    mov $1, %eax  # call system call exit on register eax
    int $0x80 #yup - interrupt it!

.type adder10, @function # like declare a function here ;)
adder10:
    #save the current base pointer first
    push %ebp

    #load the current stack pointer to the base pointer and use the new base pointer in the function
    mov %esp, %ebp

    #load the paramter on register ecx
    mov 8(%ebp), %ecx #access it using base index access method
    add $10, %ecx #do the magic

    #the return value will be on %eax
    mov %ecx, %eax

    #return the original values to the ebp and esp
    mov %ebp, %esp
    pop %ebp
    ret

Save the above file as adder.s
to run this if you are on 64 bit machine use

gcc -m32 -nostartfiles -o adder adder.s

otherwise

as -o adder.o adder.s
ld -o adder adder.o

and run it as

./adder

to see the result

echo $?

If all ok the above should print 19