Author Topic: Servlets, JSPs, Class files  (Read 1876 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Servlets, JSPs, Class files
« on: August 18, 2011, 12:49:02 PM »
This might seem like a stupid question, but what purpose do Servlets have?  It seems like a middle man to me as opposed to dealing with normal Java class files and JSP files. 

In our system, we have files that are called servlets, but they're still just classes in a .java file.  So what is the actual difference between that and a normal class file?

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Servlets, JSPs, Class files
« Reply #1 on: August 18, 2011, 01:18:53 PM »
Servlets are classes that can handle HTTP requests. They are exactly the same as JSPs (JSPs are compiled to servlets) but they are more convenient than a JSP if the class is code heavy. Basically the JSP is HTML with Java inside, and the Servlet is Java with HTML inside, you get both options and can use which ever is more convenient for the class.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Servlets, JSPs, Class files
« Reply #2 on: August 18, 2011, 01:25:00 PM »
Are you familiar with MVC concepts Ober?

Servlets really shouldn't have HTML in them and JSPs shouldn't have "Java" code in them, at least not heavy stuff like DB stuff.

Out of curiosity, what framework are you using to develop your Java stuff?
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Servlets, JSPs, Class files
« Reply #3 on: August 18, 2011, 03:34:49 PM »
Ok, that's what I've gathered so far from some basic searching on the net.  Thanks for the clarification.

tgm, I understand MVC in principle and the idea of separating the different layers, but I didn't study the theory behind it and I've never implemented it beyond using things like database object models and other classes in general. 

And that's how our general framework here is.  Most of the JSP files just have calls to methods in a Java file.  It seems that some of our team members prefer to have everything possible in the Java side while others are ok with putting more in the actual JSP files.  My current project has a little bit in the JSP file but I'm trying to keep as much as possible in our main data collection servlet.

We don't have a framework as in a packaged framework that was developed elsewhere.  Everything in the platform was built from scratch except for a few things like TopLink for cache management and JS libraries (JQuery and ExtJS).  I'd love to have something more standardized but the platform was started in 2001 and it would be a massive effort to migrate to something. 

For example, we're considering an interface upgrade since some people think it looks dated (it does).  That interface update would require touching ~700 JSP files.  :-o

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Servlets, JSPs, Class files
« Reply #4 on: August 18, 2011, 04:36:23 PM »
Probably time to start looking at moving to an MVC framework. You should definitely look into Grails on your own Ober (if you plan to stick to Java). You might find that what you guys are doing isn't really all that much effort to port over. It's amazing how much you get for very little with Grails.

A baby step might be to implement Spring/Hibernate but if it's a larger project, I'd probably just skip it and try and port it over. You might even be able to do some "new" development in Grails or something else and leave the legacy stuff until enough changes have been made that you don't need it anymore.

I know the pitch sounds awful, but the cost of maintaing the code might be close to or more. And the short term hurt is often worth the long term sigh of relief. I've had the discussion before and it's not fun but we did it and that's what made me love Grails. Looking back I fear every not having the luxuries of the language available.

There's a learning curve and gotcha's like everything else, but it's all worth it IMO.
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Servlets, JSPs, Class files
« Reply #5 on: August 18, 2011, 04:57:48 PM »
We actually have been looking at Hibernate but I haven't really been involved in those tasks.  The other unfortunate part is that the next ~18 months are already mapped out with too many projects and not enough developers.  It's kind of insane.