jsp servlet code seperation confusion

M

Martman

I posted this on the .help NG but I believe you folks could probably
provide more of an accurate answer considering the help group is
targeted towards true beginners.

Okay, where I am employeed I have the options of programming with
Microsoft Technologies and Java specifically J2EE. I have been
investigating the task of learning Java for about the last 3 to 4
months. I am a ASP.Net developer fulltime at work with C#. I was new to
OOP when I started into .Net about a year ago and am getting better.
However, our corporation uses Java as a National standard and I am
looking to advance some day and need to learn Java. Furthermore, where I
live, KY there are very few jobs for technologies other than .Net and
Java. No PHP or ColdFusion.

In the last couple of years this code seperation theory has overloaded
the programming world. .Net does it with what's called code behind. In
my research of Java the only things I see that reference code seperation
is servlets (I am sure J2EE and EJB contribute also). However,
everything I have read on servlets reference outputing HTML back to the
browser via the HttpServletResponse and Request objects.

My question, why in the world do they consider outputting HTML back to a
browser via a servlet considered code seperation. Furthermore, it
seems very time consuming and difficult to hand code complex layouts in
HTML and incorporate/format it for a servlet.

Can someone please explain or direct me to a resource where I can
understand why using servlets at any point in an application would be
better than jsp or even applets? Sometimes it's hard enough to design
complex layouts with the assistance Dreamweaver for example.

Thanks for any insight you can provide, I have read hundreds of pages of
information concerning this and trying to compare it with the my current
knowledge in the .Net world.

Marty U.
 
A

Anzime

Martman said:
I posted this on the .help NG but I believe you folks could probably
provide more of an accurate answer considering the help group is
targeted towards true beginners.

Okay, where I am employeed I have the options of programming with
Microsoft Technologies and Java specifically J2EE. I have been
investigating the task of learning Java for about the last 3 to 4
months. I am a ASP.Net developer fulltime at work with C#. I was new to
OOP when I started into .Net about a year ago and am getting better.
However, our corporation uses Java as a National standard and I am
looking to advance some day and need to learn Java. Furthermore, where I
live, KY there are very few jobs for technologies other than .Net and
Java. No PHP or ColdFusion.

In the last couple of years this code seperation theory has overloaded
the programming world. .Net does it with what's called code behind. In
my research of Java the only things I see that reference code seperation
is servlets (I am sure J2EE and EJB contribute also). However,
everything I have read on servlets reference outputing HTML back to the
browser via the HttpServletResponse and Request objects.

My question, why in the world do they consider outputting HTML back to a
browser via a servlet considered code seperation. Furthermore, it seems
very time consuming and difficult to hand code complex layouts in HTML
and incorporate/format it for a servlet.

Can someone please explain or direct me to a resource where I can
understand why using servlets at any point in an application would be
better than jsp or even applets? Sometimes it's hard enough to design
complex layouts with the assistance Dreamweaver for example.

Thanks for any insight you can provide, I have read hundreds of pages of
information concerning this and trying to compare it with the my current
knowledge in the .Net world.

Marty U.

I haven't looked at .Net at all, so I everything I say is from
a Java perspective.

You wouldn't want to hard code HTML in a servlet; it's ugly, and
difficult to maintain. Servlets are great for non-visual applications
where you need HTTP support (request, response, etc).

When you mention code separation I think you are talking about
separting the "display code", "business logic", and "control logic".
There are many tutorials on the web that mention "Model2"
development; a derivation of "MVC". Also, their are many frameworks
to choose from to assist your development. Regardless, it all boils
down to discipline and proper thinking. Think in layers and OO,
e.g. how can you separate the "model" (data), from the
"view" (display), from the "control" (logic); all comprise the
term MVC.

Alone, Java Server Pages (JSP) can be misused by incorporating
Java code as scriplets; doing everything from database connections
to business logic and application flow. A better approach would be
to only put HTML in JSPs and use Java tags to display dynamic data.
Your data would go in Java classes that follow the bean convention
with private fields and public getters and setters. Your
business and application logic would go in other classes; packaged
appropriately. While you're at it, you might as well look at
decoupling further by putting logic in a set of classes, creating
handlers that call DAO classes that handle database accesses, etc.

There are many ways to slice an application. I recommend looking
into the Apache Struts framework; It's well documented and would
be a good learning experience.

On top of all that, you still have many other areas to apply the
same principles: EJBs, RMI, etc.
 
M

Martman

Anzime said:
I haven't looked at .Net at all, so I everything I say is from
a Java perspective.

You wouldn't want to hard code HTML in a servlet; it's ugly, and
difficult to maintain. Servlets are great for non-visual applications
where you need HTTP support (request, response, etc).

When you mention code separation I think you are talking about
separting the "display code", "business logic", and "control logic".
There are many tutorials on the web that mention "Model2"
development; a derivation of "MVC". Also, their are many frameworks
to choose from to assist your development. Regardless, it all boils
down to discipline and proper thinking. Think in layers and OO,
e.g. how can you separate the "model" (data), from the
"view" (display), from the "control" (logic); all comprise the
term MVC.

Alone, Java Server Pages (JSP) can be misused by incorporating
Java code as scriplets; doing everything from database connections
to business logic and application flow. A better approach would be
to only put HTML in JSPs and use Java tags to display dynamic data.
Your data would go in Java classes that follow the bean convention
with private fields and public getters and setters. Your
business and application logic would go in other classes; packaged
appropriately. While you're at it, you might as well look at
decoupling further by putting logic in a set of classes, creating
handlers that call DAO classes that handle database accesses, etc.

There are many ways to slice an application. I recommend looking
into the Apache Struts framework; It's well documented and would
be a good learning experience.

On top of all that, you still have many other areas to apply the
same principles: EJBs, RMI, etc.

Hey thanks Anzime that really helps. You actually answered more than my
intentions with my poorly structured question. My main concern was to
seperate code from presentation and I just forgot to add the word
presentation to my question.

The good thing is you gave me a key bit of information that I needed to
help understand the code/presentation seperation concept.

Would you happen to have a link to a page that has a good info doc that
would help me understand using Java tags in jsp pages. I have searched
google but with the lack of knowledge I don't know if they are
explaining what you are referencing nor how well they are actually
explaining it.

Thanks again, big help

Marty U
 
M

Michael Borgwardt

Martman said:
In the last couple of years this code seperation theory has overloaded
the programming world. .Net does it with what's called code behind. In
my research of Java the only things I see that reference code seperation
is servlets (I am sure J2EE and EJB contribute also). However,
everything I have read on servlets reference outputing HTML back to the
browser via the HttpServletResponse and Request objects.

Then your sources are bad or you misunderstood something. The idea is to
separate display-related code from the program logic and use JSPs for
(and *onyl* for) rendering HTML pages, while servlets and regular Java
classes handle the program logic.
 
H

Heiner Kücker

The idea is to
separate display-related code from the program logic and use JSPs for
(and *onyl* for) rendering HTML pages, while servlets and regular Java
classes handle the program logic.

Ack
 

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

Similar Threads

Output confusion 2
POSTing to a servlet 4
JSP include and servlet 1
Servlet Question 2
Open popup from JSP - Servlet ?? 2
cactus and servlet redirection 0
SOA with jsp-servlet 6
jsp/servlet target 1

Members online

Forum statistics

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

Latest Threads

Top