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?
Author and all-around good cowpoke
Joined: Mar 22, 2000
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.
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 ]
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 ]
Joined: Mar 05, 2007
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.
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.
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 ]
Joined: Mar 08, 2007
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.
Joined: Apr 16, 2008
>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.
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.
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.