• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

A couple of doubts in struts

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

I was asked the following questions in an interview.I was unable to answer them as I'm just a beginner to Struts. Could someone please tell the answers?

1. Can JSP always be used instead of a servlet?

2. Which is better - using a servlet or using JSP, and what is the reason?

3. Why the Action class is not used as the controller instead of ActionServlet?

4. Advantages of Struts. Are ther any disadvantages?
[ July 26, 2004: Message edited by: Rebecca Abraham ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For servlet and JSP question, read "Core servlets and JavaServer pages" book.

For Struts Question, read "Struts in Action". This book may be too deep
for beginner. Try "Struts Kick Start" 1st if too difficult.

Sorry can't be of much help

Too lazy too look it up in those books now.

For the record, you may want to know what MVC architecture stands
for. I got asked that question in an interview

Regards


 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts User Guide
http://struts.apache.org/userGuide/index.html
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I might put in my two cents worth for the first two questions.

1. Can JSP always be used instead of a servlet?

The answer is yes and no. If the design is to separate the presentation layer with the business logic layer, then you might want to put all the business logic related stuff in the servlet. But it is always possible to write that code up in JSP, as it is another servlet (Eventually, after the page compilation). The code management becomes that much difficult.


2. Which is better - using a servlet or using JSP, and what is the reason?

Servlet and JSP compliment each other. There is nothing like one thing is better than other.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would hope that the interviewer wasn't looking for specific answers so much as to get a rough idea for the way you think.

1. Can JSP always be used instead of a servlet?
Such a question is probably best answered with defining the difference between JSPs and servlets; basically that JSPs are a special kind of servlet that let's your write html without having to write a bunch of out.print statements. With that said, it is probably safe to tell the interviewer that it is possible to accomplish virtually any functionality in a JSP that regular ol' servlet can do but it doesn't always make sense. At that point, if the interviewer had a specific answer in mind you can discuss it.

2. Which is better - using a servlet or using JSP, and what is the reason?
Hopefully this will have been answered in the first discussion.

3. Why the Action class is not used as the controller instead of ActionServlet?
Gosh, where to begin on this one? I would assume that every interwee gave a different answer (excluding perhaps "I don't know"). Again, this question might best be answered by defining the relationship between Actions and the ActionServlet which would be very difficult for a newb.

4. Advantages of Struts. Are ther any disadvantages?
This is like asking the advantages/disadvantages about life. A more specific topic of Struts would be a lot easier to answer. Like any framework, the biggest advantage is in not having to reinvent the wheel. Struts specifically though, I'd have to say navigation handling is the greatest advantage, or even just the overall flexibility. The biggest disadvantage is that you often need to slip in scriptlets (or one of the newer tag libraries) to obtain needed flexibility.

Hope some of this blabbering helps.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rebecca Abraham:
Hi,

I was asked the following questions in an interview.I was unable to answer them as I'm just a beginner to Struts. Could someone please tell the answers?

1. Can JSP always be used instead of a servlet?

2. Which is better - using a servlet or using JSP, and what is the reason?

3. Why the Action class is not used as the controller instead of ActionServlet?

4. Advantages of Struts. Are ther any disadvantages?

[ July 26, 2004: Message edited by: Rebecca Abraham ]




1. Can JSP always be used instead of a servlet?
A JSP is a kind of metadata file for a servlet, (in case your developers don't know Java, which was one of its selling points back at 1.0), and since JSPs compile into servlets, and you can override any method in the servlet hierarchy except for service(), I believe, so the answer is yes, but you may not see anything on the page depending on what it does. (Some servlets do work but display no data, etc).

2. Which is better - using a servlet or using JSP, and what is the reason?
Depends on the problem. If the problem is categorized by data retrieval and/or data displaying, then use a JSP. If it's work with little or no gui interaction required, then a servlet is better, where the ui part is delegated to a JSP through forward() or sendRedirect(). (Imagine a JSP that does work, like starting off threads in its init() method when a special 'knocking' request comes in, but the page is blank, so the user would see nothing. Not to mention it requires using scriplets, very ugly!)

3. Why the Action class is not used as the controller instead of ActionServlet?
Need to study the MVC architectural pattern. In Struts, the ActionServlet controller distributes requests to Action classes that can do the work, according to the ActionMapping section of the struts-config.xml file. For the Action classes to be a controller, they would have to be able to receive incoming requests, that is, something to control, and hence be servlets by definition. (They are not meant to be serlvets). Also, Action classes can delegate (forward) to other action classes and hence form a 2nd layer of control anyway.

4. Advantages of Struts. Are there any disadvantages?
(No order implied in my answers)
Advantages:
- You get a clean separation of model from view, and most of the hard boring work is done for you. (Don't believe me? trying building a web program that cleanly separates the model from the view and you'll see the number of extra classes you need to write is quite large).
- Well accepted technology, and hence, probably well tested. Many websites about Struts to go to for help.
- Nicely separated configuration metadata from actual implementation, it's all in a struts-config.xml file. (That file can be broken into sub-config files, too).
- Easy to install in all available web containers, like Tomcat. (It's little more than a bunch of jar files you put in the right folder).

Disdavantages:
- Struts has a learning curve, like all technologies. Is it worth the developer's time to study, learn, and debug using the Struts framework? (Surprisingly, the answer isn't always going to be yes).
- It's open source. (Large companies will often baulk at using open source stuff. They like to sue people if a technology fails them in some way).
- It's built around one thing, the MVC design pattern, used for separating the data (model) from the presentation (views). If you don't have ui views, (i.e. webs services?), then MVC may not be a good pattern to use and hence Struts may not help you as much as you think.
- I've also heard it doesn't scale well to extremely large sites. (Do you think Amazon.com uses Struts?) Struts may or may not be beneficial to portals, I'm still investigating this.
- There seems to be no standard configuration tool to set up Struts. You need to organize your projects folders for action clases, form beans and so on, yourself. People, we need a graphical Swing tool to define the action classes and form beans and build the xml file.
Let's face it, the struts-config.xml file will grow as large as a DD in EJB soon. Wanna edit that by hand in the future?

Jeff Walker
 
Greenhorn
Posts: 6
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to answer the first question (jsp or servlet), the best way is to see from the point why jsp arised.

jsp was a hurry technology, which was released to compete with microsoft's asp. so there is always a little confusion on placing the business logics in either jsp or servlet. in my view always executing business logics in servlet is safe, but it worth time.

but with the jsp2.0, approach to jsp programming is totally changing. here after, jsp programming is going to be web designers' work, rather than business logic developer. business logic developer is going to provide the stuff in tags, while the web designers' are going to use the business logic tags, just as html.

a big salute to jsp2.0

regards
mathi
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic