Is it possible to build a Java web application without using a framework?

12,667

Solution 1

You can go a very long way with just servlets and JDBC. Consider JSPs using JSTL as an added nicety.

But I'd bet that if your web site consists of more than a page or two delivering database content to the browser, you'll quickly discover why web frameworks are so numerous. Hard-wired page navigation, control logic, blurred layers, etc. will cause headaches as your site grows.

You'll find you have a lot of similar, repetitive, but slightly different code for each bit of new functionality. If you have to maintain a site and keep it going, eventually it's likely that you'll reach the conclusion that there are patterns ripe for capturing. Who knows? Maybe you'll decide as a result of your experience that you want to take a crack at solving the web framework problem, too.

Whatever you do, I think having distinct layers is key. Don't have servlets do all the work - they're for handling HTTP requests. Embed the work in service classes that your servlets can simply call. That way you can reuse that logic. Keep persistence code in its own layer and don't let it leak out into others. You can have reusable components that will survive your first efforts. If you decide to switch to a web framework you'll just snap these layers into place and off you go.

I wrote my first significant web site without any frameworks - just straight servlets, JSPs and JDBC. It gave me a better understanding of what was going on. I think it helps.

Solution 2

Check out Head First Servlets and JSP for the fundamentals of building Java Web applications without using complicated frameworks. It's good to understand what's going on behind the scenes when you use a framework, and this book is a great introduction.

HFS&JSP
(source: oreilly.com)

Solution 3

Yes, definitely. Java can seem rather paralyzing with all of its frameworks; however, you can certainly build great web applications by rolling your own infrastructure. That being said, I think Spring is a great framework to look at it and is very well documented and supported.

Solution 4

Yes, absolutely. Go ahead, and don't let anyone discourage you! Back in the day, the first solo-flight project a new java programmer would write would be something to suck porn from thehun.com . I applaud the maturity of our young programmers these days.

Solution 5

Yes, it is possible. But it seldom makes sense, because you would have to implement all needed functionality from scratch by yourself. This takes a lot of time and effort and often yields worse code than you would get by using a framework. Learning a framework also takes some effort, but once you learn a framework, you can easily use the knowledge on your next project.

Share:
12,667
user62617
Author by

user62617

Updated on July 26, 2022

Comments

  • user62617
    user62617 almost 2 years

    If not what is a good friendly java framework for newcomers?

    I want to build something like twitter.

  • Christian Nunciato
    Christian Nunciato about 15 years
    +1 for recommending this -- it just might save me on my next project. :)
  • Bill the Lizard
    Bill the Lizard about 15 years
    @Christian: It definitely saved me on a project once. Of course, that was back when Struts was the only framework to speak of. :)
  • T J
    T J over 6 years
    I see the same content here: bayt.com/en/specialties/q/6756/…. Possibly stolen without attribution unless you are "taymoor qanadilou"
  • duffymo
    duffymo over 6 years
    I am not. Clearly stolen. I wrote this almost nine years ago.
  • duffymo
    duffymo almost 5 years
    "You can go a very long way with just servlets and JDBC. Consider JSPs using JSTL as an added nicely" - there's your no framework answer. The answer is more than TEN YEARS OLD. You should be able to think of a better way to burnish your reputation here. Besides, I didn't cite a single framework. Your reading comprehension needs work.
  • duffymo
    duffymo almost 5 years
    Spare me your frustration. You ought to take it out on the people who asked you to do something unreasonable, not me. Point out where I mentioned Spring (Hint: It's not there.)
  • Arun Gowda
    Arun Gowda over 4 years
    " It gave me a better understanding of what was going on" this is exactly why I want to build a simple web app without any framework. Just pure Java