Solved

java bean, JSP and Servlets

Posted on 2001-07-30
7
724 Views
Last Modified: 2013-11-24
1) what is java bean?

2) for e.g. i am developing a web application, i am using servlet as my back-end language. If servlets can do all the task why is JSP needed. the point to this question is i can't see the significant of servlet combining with JSP. some of my friend say that the combination of jSP & servlet can make the application faster. Is this true?
is there any other reasons.

3) what are the advantages that java servlet have over java applets?
0
Comment
Question by:volca
7 Comments
 
LVL 3

Expert Comment

by:black
ID: 6333331
a java bean is simply a class that has getters and setters
i.e.

public class SimpleBean {
     private String hello;
              private String world;
  public void setHello(String hello) {
    this.hello = hello;
  }

  public String getHello() {
    return hello;
  }

  public void setWorld(String world) {
     this.world = world;
  }
  public String getWorld() {
     return world;
  }
}

there are tags that make it easy to use beans:
http://devx.experts-exchange.com

The servlet should handle the request do some processing and put the result of the processing (a bean containing the results) into either the session or the request. Then the JSP can get the data and present the results.
The JSP should be mainly HTML or the type of  output you are using for the GUI, you should simply get the data in the bean and place it in the right place.
The JSP should be mainly presentation i.e. HTML with a bit of Java, the servlet should be all java with no HTML.
0
 
LVL 3

Expert Comment

by:black
ID: 6333332
Java applets are a client side application, the user would download it an run it on their machine, a servlet sit's on your server accepts requests from users and gives output back in the form of HTML,XML or any other format you want.
The basic difference is the Applet runs on the client, Servlet runs on the server.
0
 
LVL 3

Expert Comment

by:black
ID: 6333335
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:yerkan
ID: 6333560
Hi

The JavaBean-Servlet-JSP represent the separation of logical layers of your application. The JavaBeans components represent the Model (basically business rules, data), the Servlet is the controller and the JSP is the view of the corresponding data.

Ideally, the model is supposed to be business specific and application neutral. You may be able to reuse your JavaBeans with a desktop application doing the same job than your Web Application. They should perform the same task without problem.

The controller (the Servlet or the Servlets) acts like a dispatcher. It knows the relationship between the data and the view and decides which view renders which data.

The view is the application specific presentation of the data.

My prefered example on this topic would be "a basic statistics application". Imagine you want to represent three different data: A=50%, B=30% and C=%20 and the data comes from your database. The JavaBeans extracting this data are application independant because I can create a desktop application or a Web Application, they will give me the same data. Now, you can represent this data on different charts: 3D on your Web app and as a "Pie" shape on your desktop application. Then, I change the data on the database and because the views listen to the same model, they all change accordingly. I hope you see the advantage of separation now...

Have a look at this link for further explanation:
http://www.uidesign.net/1999/papers/webmvc_part1.html

Regards,

    Yagiz
    http://www.erkans.com
0
 
LVL 1

Expert Comment

by:Recall
ID: 6333672
In my experience I have used either servlets, or the pairing of JSP and Beans.

When you use JSP (with calls to Beans which provide the processing elements of the page), the JSP engine compiles your JSP page into a servlet (with calls to Beans blah blah).

From a performance POV, you would expect the JSP engine to create a servlet optimized for the engine in some way I guess.  Of course this is totally under the control of the JSP engine, so it depends to an extent how good the JSP engine.

The advantage of JSP is that it abstracts out to a large degree the form from the content.  I.E. You "design" in the JSP file your layouts and colours etc, and use calls to the Beans to provide the processing elements e.g. dynamic content.

Recall
0
 

Accepted Solution

by:
prakash_mas earned 200 total points
ID: 6333981
>1) what is java bean?
 Java beans are the simple java program , which follows some set of rules ,
some of the rules are like having get/set methods ...must implement specified interfaces( in case of EJB)
basically all this rules are made so that bean object can be created / accessed transparently to the developer i.e developer need not have to bother about the creation/destrection ...... of bean ...this is becoming   powerful fetere of J2ee as EJB, and also used extencevly in JSP while implement CVM patterns



> 2) for e.g. i am developing a web application, i am using servlet as my back-end language. If servlets
>  can do all the task why is JSP needed. the point to this question is i can't see the significant of
>  servlet combining with JSP. some of my friend say that the combination of jSP & servlet can make the
>  application faster. Is this true?is there any other reasons.

Yes servlet can do all the task what JSP can do , but as a web developer where it will be easy to maintain the application, reuse the application if  the code is in nutral language( as html , xml...) using JSP we can acthive this for greater extent .
   JSP is more close to presentation layer , core servlet is used when there is only back ground process is required with minimal presentation.
    JSP and Servlet are combined in many application mainly while implementing   CVM( Control View Model ) pattern where JSP comes in View portion , servlet in controler and normally beans(Or servlets ) as Model .
    By this pattern application is prooven to give high performance as in most of the cased one servlet will control  many JSP's and beans.
    At last all JSP are intern converted to servlets before executing , Soooo  if any one is very goood servlet program and can write highly reusable / maintanable modulesas JSP ,  JSP implementation is not required atall  

> 3) what are the advantages that java servlet have over java applets?
Servlets are the server side program and applet is for client side program ,
so there is no point in discussing diff/ advantages of these both , if you still want to
know about this u can contact me at prakash_mas@yahoo.com, i will be glad to explain .
0
 

Expert Comment

by:SpideyMod
ID: 8289595
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now