Roles of JSP, Servlet, and JavaBean in Web Applications

Source: Internet
Author: User

 

What roles does JSP, Servlet, and JavaBean assume when writing Web applications?

 

You can think of this idea as a typical MVC control mode.
JSP to display data, ____ view;
Servlet control page transfer, ---- control;
JavaBean business processing, ---- Model
Model is used to process logic. That is to say, you can put the content of the database to the JavaBean, while JSP is only responsible for displaying the corresponding data. As for servlet, you can think of it as a controller. jsp will send the request to the servlet, the servlet differentiates the corresponding tasks based on different tasks and submits them to the bean for processing, that is, the model.

 

--------------------------------------------------

Pure JSP/servlet/JavaBean development means that no EJB, struct... wait a moment. during development, I often think that it is better to use JSP + JavaBean or JSP + servlet + JavaBean or JSP, still use JSP more? More JavaBean? More servlets? Especially when someone else sees a project, they only use one servlet, and each of their own functions may have several. I really can't think of it. Sometimes I can't tell it.
Please be grateful if you have any experience!

-----

Design JavaBean first, because this is the main body of the program
Consider design patterns, efficiency, structure, portability, reusability, and so on,
Design a large framework.
This is mainly the M and model in the MVC mode.

Then create a page with JSP, mainly to make a set of beautiful foliar
Try not to write code in JSP. You can consider using struts
This part is in the MVC mode V, View

Servlet is mainly used to process requests.
Create a controller. Java and then submit each JSP page
To write different actions, write a complete set of actions, and use the policy mode.
This part is the mvc c, Controller

So what structure is used mainly depends on your design
If needed, use it. If not, use it.
The so-called only one servlet, may be the controller, the action is handed over to the action

 

----

To gianfeng (xiaotong)
I usually write a lot of code to JavaBean. I put all the Code involved in data processing in servlet.

Cannot be generalized.
Servlet mainly processes the request and determines which action to process, which is equivalent to the main function previously written.
Action is used to process data, which is equivalent to the previous process function.
Javabean is actually a class containing Fixed operations, which is equivalent to a library function!
Struts, similar to a diaglog, accepts user input and sends it to Servlet

In fact, do not worry about writing programs. Learn more slowly,
The key is not to always do useless and repetitive work.
For example, I am taking some work now. If it is a static website or an ASP Website, I will not do it if I have more money.
You can do this only when you are able to learn something and get something.

 

----

Note: supplement the above,
Javabean is the core of background technology. Do not create database functions !!
Use object-oriented thinking to write Java programs
Some people use Java to write a set of process-oriented things. I almost fainted.

Always consider: Is my class the best? Can it be simplified?
Can I use this class again next time? Does this class have something in common with another class?
Can we abstract commonalities?

In the design pattern, abstract programming is required, meaning that each line of code should not be specific
Your final class. It must be oriented to an interface or abstract class. This facilitates porting and adding features.

-------------------------------------------------

 

--- From csdn

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.