• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Web Frameworks

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have been working with Java for about a year now and have slowly progressed from small command line programmes to jsp pages with scriptlets, to using beans and finally to using JSTL. I have been expecting my next step to be using some sort of web framework but have come up against a few issues.

First of all, for me as a programming newbie, the configuration and some of the concepts of typical frameworks (Struts, JSF etc) are a bit overwhelming. I am constantly trying to make my next project better organized and more up to date than the previous one so for my latest (building a new Intranet that will house custom tools and building some of those tools) I started looking at MVC frameworks. It felt like it was going to take longer to learn than I really had available to me at the time. I thought to myself, I'll try to work myself into it by first using JSTL.
This has improved the look of my code a hundred times and it horrifies me to see my old pages, covered in scriptlets! Then I looked at frameworks again and it seemed to me that they were more effort than they were worth so I decided to take a different path that would at the same time give me some more Java experience.

I have written two programmes, one to read a database table and create a bean and another to read a bean and create a form. I don't know whether this is a good or bad way of doing things but in my beans I have a setPopulate method which fills in the bean from database data and getValidation which carries out server side validation and puts bean data into a database.

My web pages have no business logic in them, JSTL is just used for presentation logic. I do use individaul 5 or 6 line jsp pages as 'controllers' when submitting forms however. They usually contain no more logic than the following


I can now create a Web application in a very short period of time. I just create a database table, run my two programmes, fill in the serverside validation in the bean's getValidation method and finally put a line into a standard jsp that includes all my css and headers and footers etc.

Now I know that there must be a reason why more people don't do what I am doing but what is it? I want to move on and still think I should be using a proper web framework (if for nothing else than to make my CV look better)! But what do these frameworks do that my present way of doing things doesn't? How would they make things quicker for me?

Also, does anyone have any interesting opinions about the current 'I must use an MVC framework' trend?


Thanks.

P.S. If anyone wants any of my code, feel free to ask. It's only basic at the moment but I plan to make it into an Eclipse plugin and any help or suggestions would be greatly appreciated. Like I said, I'm still only a begginner so you may look at it and think it's a bit dodgy but if you could tell me how I should change the way I do things or if you would like to contribute that would be fantastic.

P.P.S. Am I posting this in the right type of forum?

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David J Smith wrote:
P.P.S. Am I posting this in the right type of forum?



Will be better suited in our JSP forum. I'll move it there for you
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not alone in your views. There are those, like myself, who would not use Struts, SpringMVC, or an abomination like JSF, unless a very large man, probably with a weapon, forced me to.

For myself, and anyone else who wants to use it, I developed Front Man -- a simple Front Controller implementation that is all the "framework" I need.

I take no short cuts -- I follow good practices and adhere to standards -- but I don't need all the goop that comes along with the big frameworks to do it.

Personally, I would never be sloppy and submit to a JSP just because it's convenient. But you get to make that call for yourself.

There are those that swear by the big frameworks. To each. Whatever makes you productive.
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you always submit to a Servlet? I've never used Servlets so I didn't even think of that but I suppose that's the way to do it.

How do you pass your session beans to the Servlet?

The Servlet is then the controller so that would be the missing element in my MVC really.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"session beans"? Not a JSP or servlet concept. EJB?

With regards to modern, best-practice web app structure, perhaps this article will help.

If you are going to "go it alone" without the crutch of a framework to beat you into submission, it is very important to understand the concepts and best practices so that you aren't just digging yourself a hole that you might never emerge from.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like Bear says--it's a matter of what works for a particular application. I wouldn't use Struts 2 or Spring MVC or whatever for a tiny application with very little logic. (Well, I might, actually, but I'd consider not.)

If I *was* using a minimal approach I would *definitely* split up my view and server layers between servlets and JSP, although my servlets would still use business objects for any actual processing. This is so I could test it outside of a servlet container. I might use something as a minimal controller.

You don't really "pass" session beans to servlets, you retrieve them from within servlets.

Note that something like Wicket or Tapestry might not be considered MVC but a different, component-oriented approach to web apps.
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had just finished reading that article actually!

So what I mean is:

At the moment I am working on a project where I have a load of HTML forms that constantly need to be changed and updated etc. Obviously, using a basic Java Bean with

makes sense. The forms are mapped to beans where I can put all my logic for validation and database work etc. When saving these forms I am submitting them to jsps where really I should be submitting them to a controller servlet? My question is, how do I get the servlet to read these beans?

it is very important to understand the concepts and best practices so that you aren't just digging yourself a hole that you might never emerge from.



That's why I posted this!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terminology: beans placed in the session are not "session beans" but "session scoped variables".

Again, submitting to a JSP in order to use <jsp:property> to gather the form values into a bean is a hack that I would not use. I submit to a servlet and either gather the form data "by hand" or use the assist of the Jakarta BeanUtils project to do the same sort of thing that getProperty does, except in Java code.

All of my business logic is not mixed in with such beans, but completely segregated in a layer that could be used with any UI, not just a web UI.

Retrieving beans (or any other data from) the scopes is done with the getAttribute() method of the particular scope (request, session or application/ServletContext).

Grab a copy of the Servlet Specification and read through it. It's an easier read than you might expect.
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wouldn't use Struts 2 or Spring MVC or whatever for a tiny application with very little logic.



That's the thing, some of my work has loads of business logic in it and I can't see how that changes things. I have 1 method in my bean that works out what it should do with the information based on what values are in the bean then does it. This never ends up being many lines of code as it is usually asking other classes to do the stuff. If I get my code to do loads of weird and wonderful stuff, how does that change the web end of things?
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

All of my business logic is not mixed in with such beans, but completely segregated in a layer that could be used with any UI, not just a web UI.



The beans have absolutely nothing in them that links them to a web UI. They are just a load variables with accessors for each variables. They do not extend any other class (unless I want them to have some methods easily available such as DB connections or something like that). The UI populates the variables and reads the variables and that is it. As far as I can see, it is completely separate. I could write a Swing UI and use the beans without changing even 1 line.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent!
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not trying to prove a point or be stubborn or something, I really just want a bit of advice on how I should be doing things (like now I'm going to start using servlets I think) and why I should do these things. What is the reason. I don't want to just start doing things for no reason other than I think I should. So far I've got:

1. You shouldn't submit to a jsp
I'm going to stop doing this and start using servlets

2. The UI and business logic aren't completely separated
It looks to me like it is? I could change UI without changing any business logic.

3. It's ok for simple apps but gets more complicated when you have more business logic.
As the UI is separate, I don't see how it gets any more complicated?

I've already learn't some useful terms and to start using servlets so it's going well so far!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you're on-track to me.

And with regards to (3), I agree. While more complicated business logic may mean a broader UI (to represent all those business rules), it doesn't necessarily mean a more complex UI.

You've already over-come two hurdles that many web developers seem to grapple with:

1) You've already realized that scriptlets in a JSP are a badge of shame

2) You've grokked the concept of Separation of Concerns

Now it's just a matter of applying the servlet and JSP technology at your fingertips. I stress again to read through the Servlet Spec so you understand the underlying concepts thoroughly and know what is available to you.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also want to look over a lightweight framework named Stripes.

Not necessarily for use (unless you really like what you see), but just for additional exposure to concepts.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[thread hijack removed -- please ask your own questions in your own new topic]
 
David J Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, thanks for all your help.
reply
    Bookmark Topic Watch Topic
  • New Topic