"localhost:8080" works fine but "localhost" doesn't
"localhost:8080" works fine but is it mandatory to give the port number always, because it doesn't work when I just type "localhost"
The IANA has assigned 80 as the HTTP well-known port number.
So browsers use this port by default.
If something is listening on a different port, you have to specify the port.
If you want your localhost-listening webserver to accept requests on port 80, you need to configure it to do that.