• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why servlets

 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have done server side scripting on JSP and have used it to effect in accessing (xml, SAX, JDBC) etc.

My Question is that, does a good Java Web Component Developer also need to know the ins and outs of a servlet? Most job interviewers ask about servlet lifecycle etc. Why? It IS true that every JSP gets translated into a Servlet, are there some things that can only be done optimally through a servlet and not a JSP Page OR when would a developer have to write a servlet and not a JSP Page?

For Example I was asked to write a dispatcher servlet at work. Why do this? Why not just create a JSP Page?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Question is that, does a good Java Web Component Developer also need to know the ins and outs of a servlet?


Short answer: Yes

If you will browse through the recent posts in this and the JSP forum you will see plenty of cases where "developers" got in trouble due to not knowing the ins and outs of the servlet API.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are meant to create the "view" of web app pages. Using them for processing is a misuse of the tool in the same way that using a hammer to whack a screw into a board is a misuse of a tool. Sure, you can get it to work, but the results aren't pretty.

The fact that JSPs are translated into servlets is an implementation detail that cannot be used to justify the misuse of JSP.

You may find this article helpful.
[ April 14, 2008: Message edited by: Bear Bibeault ]
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Bear.

Your article gave me a fairly good understanding of MVC.

Thanks again!
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dig into some very well-known frameworks like struts to know why Servlets ...
 
Ashimashi Kabashi
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I realize that.

Can you suggest a good place to start struts. There are plenty available once you google, but can you recommend any?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would strongly advise against Struts until such a time as you have a good understanding of Servlets.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't actually learn it deeply as Mr.Bear mentioned.

Just get an overview of the ActionServlet.

Regards,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better yet, just learn about the Model 2 (web app approximation of MVC) and Front Controller patterns. Again, I'd advise ignoring Struts completely until you understand the underlying basics. It'll just confuse you.
[ April 14, 2008: Message edited by: Bear Bibeault ]
 
Anshul Malpani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See there is specific use of servlet. Not for Design purpose.
One more thing Understanding the JSP properly you should have good knowledge of servlet. Servlet takes less time to load in memory compare to jsp. Because translation time involves.

If you are Java programmer you will find Servlet is good for writeing the java code.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anshul Malpani:
One more thing Understanding the JSP properly you should have good knowledge of servlet.


I find the opposite to be true.
If you understand servlets, it's a lot easier to decipher what JSPs are doing.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If one is just starting out to learn Java servlet programming, then learning by way of Apache Struts framework is a good step. Once Struts is learned, then a good understanding of why, how and when to use servlet, JSP page, custom JSP tag, etc. will be developed.

Learning how to use and build web applications with Struts will also help with understanding MVC design pattern implementation.

Basically, Struts provides a Controller servlet (ActionServlet) that application developers customize via Action classes and XML-based configuration files. With a instance of a Struts skeleton, applications can be developed quickly and in accord with practical design strategies.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Clark:
If one is just starting out to learn Java servlet programming, then learning by way of Apache Struts framework is a good step.
I strongly disagree. It has been my experience that diving off into Struts, or any other obfuscating framework, prevents people from learning basic JSP and Servlet skills. Instead, they just learn the framework without understanding how the underpinnings work.

Learn the basics first -- then decide if or when a framework is warranted, and then which one.

I do agree that learning important patterns such as Front Controller, Command (what Struts incrorrectly terms "actions") and MVC are crucial. I just don't think that adopting a framwwork such as Struts at the outset is the best way to do that.
[ April 16, 2008: Message edited by: Bear Bibeault ]
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Mr.Bear

To tell about my situation, i have learning about struts once, i understood the general idea, but, things were unclear.

After passing my programmer exam, i have decided to do my SCWCD, and after buying the Head First Servlets and JSP book, i have started understanding all the deep secrets of java web components.

Not only you can understand struts of any other web frameworks after understanding the core components, but you can really build your own framework as well.

Many companies now have their web based MVC framework.

And to be more honest, i enjoy dealing with core Servlets and JSPs more than dealing with Struts (although struts is a great thing) itself, do you know why ? Because i control each and every component in the application.

Now, dealing with frameworks has great advantages, but the main point is to be great at the core technology.

Regards and thank you for reading my long post.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>I do agree that learning important patterns such as Front Controller, Command (what Struts incrorrectly terms "actions")..

The Action class is part of the ActionServlet, i.e. Front Controller. The ActionConfig class is also part of the ActionServlet. These classes enable the developer to customize the ActionServlet for their application.

I am not familiar with the association of the Struts Action class and the Command design pattern. As mentioned, this is not correct. The Struts Action class DOES NOT implement the Command pattern.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could very well go with what Bear has been suggesting and insisting!

Learning Struts at first is like doing your Hello World Java program in a well known editor like WebSphere, WebLogic, eclipse etc., Instead what is suggested to get the best out of the "technology" is do with your 'command prompt' and invoke the 'javac', 'java' executables to get to know the real effect and knowledge.

The same holds good here!
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

With regards to all posts referring to MVC framework and the likes, may I suggest that to act as a dispatcher is not the ONLY case we would need a Servlet for.

Another example could be when the response 'type' is needed in a format other than HTML (say, GIF, PDF or XLS). This can be easily achieved by writing Servlets using corresponding API (like iText for PDF) to dynamically prepare the response.

As a JSP gets translated into a Servlet, its always recommended to know the in-outs of Servlets. IMHO, JSP should be the second-step in learning after Servlets. That is more natural and helpful, at least to me.

Best regards,

- Aditya Jha
[ April 28, 2008: Message edited by: Aditya Jha ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic