File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp vs servlet, stardard tag vs javabean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp vs servlet, stardard tag vs javabean" Watch "jsp vs servlet, stardard tag vs javabean" New topic
Author

jsp vs servlet, stardard tag vs javabean

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, confuse here ,
1)when should we use servlet rather than jsp?
2)when we should use stardard tag rather than javabean , can i just fully use on stardard tag ?
3)normally in a web application, how the pratice should be ?
thank in advance for answering !
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
JavaBean is used in the context of jsps. But it is mor of a server side aspect and can not accomodate complexity as does a custom tag.
With respect to Servlet vs JSP, servlet is more preferable as controller for client side to tap the enterprise.
JSP has the advantage of ease of use to develop clients for a web application. But servlet also plays a part in the sense of tapping the correct services on the server.


Kishore
SCJP, blog
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Alvin,

1)when should we use servlet rather than jsp?

In the past, due to the lack of powerful IDEs, I think Java Developers will write Servlets, while Web Designer may write JSPs since they can put HTML there with some simple JSP scriptlets.
Nowadays, by making use of MVC model II architecture, JSP is mainly for presentation. The real thing shows the clients is put into the JSP. Servlets act as a Controller, to control the workflow (or the actions to be performed), either to get the data (from either DB or other systems) or forward the requests to other JSPs.

2)when we should use stardard tag rather than javabean , can i just fully use on stardard tag ?

what do you mean by stardard tag? JSTL or JSP 1.2 tags?
JavaBean is very useful when you have a html form to be submitted. When you have a JavaBean that contains the same name of all form parameters together with the getter and setter, you need not to do anything and the container will pass all form parameters to the JavaBean and save it in the bean. However, JSP 1.2 tags do not have such capability.
But for now, since Struts' invention, Struts can do the same thing, and I think JavaBean is not that useful nowadays. JSTL does the standard HTML tag display, and JSF does the component level. Together with Sturts, the web application become more fantastic.

3)normally in a web application, how the pratice should be ?

It is difficult to say. In general, I think we can do this:
JSP for presentation.
The standard HTML tag inside the JSP can be replaced by JSTL.
Servlets (basically can be together with Struts) is acts as controller.
Tiles can be used to be the template of web pages.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

The standard HTML tag inside the JSP can be replaced by JSTL.

No they cannot.
JSTL has nothing to do with the HTML tags, let alone replace them. The JSTL tags are used to perform server-side actions that used to only be available via JSP scriptlets and scriptlet expressions. They are in no way a replacement for HTML markup.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Bear,
Even 10 certifications can start giving some false information
Dan.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Bear,
Oh, I have mixed up with the Struts tags.
Those HTML forms can now be defined by the tag:
<html:form> ... </html:form>
Sorry for the mistakes.
Nick.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
thank you for giving me so much valuable comments , thks !
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136

and I think JavaBean is not that useful nowadays.

I'd certainly venture to disagree with that.


for (int i = today; i < endOfTime; i++) { code(); }
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65


... and I think JavaBean is not that useful nowadays.


I'd certainly venture to disagree with that.

In fact, with the advent of JSTL, the JavaBean pattern may be said to be more important than ever in the world of JSP.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
can javabean replace by custom tag library ?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
It really depends on how you think.
I guess nowadays, especially the invention of Struts, we can use another form to provide JavaBean.
For example, when I have a HTML form that captures parameters, if we use Struts, and if we define, say, a form named paramForm. When we click the submit button, the data inside the HTML form will be automatically set into the paramForm. In addition, we should use Struts' tags so that the Dispatcer knows what to send and keep.
In the ActionDispatcher, we can access the Struts form and get the values of the HTML form from it directly. This Struts form in fact doing what JavaBean does in the past.
I am sure that, there are still many developers writing JavaBean, but my company has already adopted Struts, and using Form instead of traditional JavaBean. I guess this maybe the trend, if Struts gets more and more popular.
If you regard Struts' tag is one type of custom tag, in fact, they are not replacing each other, but supplementary to each other.
Nick.
[ March 11, 2004: Message edited by: Nicholas Cheung ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by Alvin chew:
can javabean replace by custom tag library ?

Certainly not.

Might have lost in importance a bit, but the use of beans to store information has only increased as it should.
Remember that ALL Java classes can effectively be beans if you code them with properly named getters and setters (and officially if you make them serializable).


42
John Brace
Greenhorn

Joined: Apr 15, 2004
Posts: 1
Originally posted by Jeroen Wenting:

Might have lost in importance a bit, but the use of beans to store information has only increased as it should.
Remember that ALL Java classes can effectively be beans if you code them with properly named getters and setters (and officially if you make them serializable).

Ahh Java... I remember those university classes well. The question though is - how many people use Java? It takes a while to load on most machines... and I've fixed a W98 machine in the past that got a worm through a Java exploit.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by John Brace:

Ahh Java... I remember those university classes well. The question though is - how many people use Java? It takes a while to load on most machines... and I've fixed a W98 machine in the past that got a worm through a Java exploit.

Despite sounding like a troll, let's discuss this a bit...
The current estimate is that there are some 2 million people developing using Java. That excludes the probably tens of millions of people using Java software without often being aware of it (the customers of those 2 million).
Your exploit was most likely a Javascript exploit rather than a Java exploit, an error some people are want to making (sometimes deliberately in order to blame something on Java that they know they shouldn't).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Had Jeroen not replied with such an informative response, I would have merely deleted the troll as off-topic.
John, if you are a serious poster to the JavaRanch please be sure your entries are on-topic for the disucussion. If you want to discuss Java usage and related topics, we have forums for such. If you are not serious, you will find that your posts will not be tolerated long at the Ranch.
 
jQuery in Action, 2nd edition
 
subject: jsp vs servlet, stardard tag vs javabean
 
Similar Threads
abstract class vs interface ?
JSP Vs (XML and XSL)
jsp vs servlets vs. beans
PHP vs JSP
Local vs. Remote Interface