Separate business from presentation

S

Sboffo

It is a good practise to build servlet for business (DB access)
and servlet for presentation (HTML).

Logically it is light, but the problem is to send data from
the first to the second, in particular way when data is big.

If I get a lot of data from DB, how can I send them to the
presentation servlet?

My solutions are:
-using session (quick to build, but slow to execute)
-using XML (slow to build, and maybe slow to execute)
-using array of object (slow to execute: the add method
is slow).

How do you thing to be the best?
Why?

Thank you very much.
Ferro.
 
D

Dobromir Gaydarov

Sboffo said:
It is a good practise to build servlet for business (DB access)
and servlet for presentation (HTML).

The good practice is to have the servlet delegate the business logic to some
helper classes (if not using EJBs) and the presentation to a JSP.
Logically it is light, but the problem is to send data from
the first to the second, in particular way when data is big.

If I get a lot of data from DB, how can I send them to the
presentation servlet?

The data (Model) is normally passed by the servlet (Controller) to the JSP
(View) as attributes to the request object.
From separation of responsibilities perspective the data should be in the
form of Java Beans, so the person writting the JSP is not required to
understand java at all (he knows how to use its HTML editor that happens to
know about Java Beans specification).
My solutions are:
-using session (quick to build, but slow to execute)
No, someone has to clean up after that. That is why in the request - it will
be thrown away.
-using XML (slow to build, and maybe slow to execute)
No, XML is too slow and therefore recommended for data exchange between
applications (written in different language by different vendors and so on),
but not between the Controller and View in the same program. If someone
tells you the opposite - that is just a buzz word.
-using array of object (slow to execute: the add method is slow).
???

Regards,
Dobromir
 
F

Ferro

The data (Model) is normally passed by the servlet (Controller) to the JSP
(View) as attributes to the request object.

But some times I need to pass a lot of data: 200-300 record with 10 fileds
everyone.
Is it more efficient REQUEST or XML?
Remember that servlet has to:
-READ many data from DB
-WRITE many data to request
and JSP has to:
-READ many data from request
-WRITE many data to response.
From separation of responsibilities perspective the data should be in the
form of Java Beans, so the person writting the JSP is not required to
understand java at all (he knows how to use its HTML editor that happens to
know about Java Beans specification).

I know JSP and servlet, but don't know JavaBean: but are JavaBean more
elegant or more quick than request?

[OT]: Can I mean JavaBean as Servlet client side?

Class pippo{
public int field1;
...
public int fieldN;
}

pippo data_from_servlet_to_jsp = new pippo[];

Do you understand?

Ciao, Ferro.
 
C

Christophe Vanfleteren

Ferro said:
But some times I need to pass a lot of data: 200-300 record with 10 fileds
everyone.
Is it more efficient REQUEST or XML?
Remember that servlet has to:
-READ many data from DB
-WRITE many data to request
and JSP has to:
-READ many data from request
-WRITE many data to response.

That's not that much data, and putting the data in the request is not slow.
Have you actually tried it, and benchmarked it? Or are you just assuming it
is slow?
From separation of responsibilities perspective the data should be in the
form of Java Beans, so the person writting the JSP is not required to
understand java at all (he knows how to use its HTML editor that happens to
know about Java Beans specification).

I know JSP and servlet, but don't know JavaBean: but are JavaBean more
elegant or more quick than request?

[OT]: Can I mean JavaBean as Servlet client side?

Class pippo{
public int field1;
...
public int fieldN;
}

pippo data_from_servlet_to_jsp = new pippo[];

Do you understand?

Ciao, Ferro.
 
F

Ferro

That's not that much data, and putting the data in the request is not
slow.

Do you think so when 250 users run on server?
Maybe they aren't concurrent, but maybe 100 users can be!
Have you actually tried it, and benchmarked it? Or are you just assuming it
is slow?

:))))))
I try to understand the problem.
I will do it.
But to do it, having some thought about it, is different.

Thank you.
Ferro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top