Rakesh Bhat wrote:
>
> Hi Laskowski,
>
> As I understand , one uses JSP over Servlet because writing a JSP code is simpler
> compared to Servlet.Right ?

Yes, but watch out you can fall into a trap and you may mess up your JSP
and HTML so nobody will know what is in.

> They are 2 different server side technologies.
> I agree that JSP finally compiles into a Servlet.But , i don't understand why one
> will use JSP and servlet together ?

See below.

> When you use JSP , all the objects like request , session... are available
> implicitly which you get in servlet by extending HTTPServletRequest class. right ?

True.

> So why one will use Servlet with JSP? As I understand one uses Java code in a
> separate bean because he/she wants to hide the business logic. Right ? Why to keep
> the same code in a servlet ?

Who told you that the same code should be in JSP and servlet as well ? I
didn't.

> Is my thinking correct or am i missing here something ?

Yes, you're almost correct:) Take a look at the series of Java code and
give yourself an answer on the question which one is simpler to read and
maintain. I think that you didn't work on large project(s) which use
loads of JSP, Servlets and (probably) EJBs. In such projects, you
wouldn't be able to write all the code because of time you would spend
on it. Another aspect is knowledge you could bring to a project. One is
very familiar with HTML code, another with JSP Tags, and another with
servlets, yet another with EJB and so on. Having such people in one
place, you could start coding without a need to infere with each other.
Everybody could work in his/her own way and during last days of
development all the code could be bring together and it should work. Of
course, you would have to define objects which could fly from one side
to another, but that's it, nothing more, nothing less. The best thing is
that you could fire one of developers and hire another one who has
experience in doing one thing, say, HTML+CSS+Java Script or Java
programming in general or JSP/Servlet programming or...

That's not new thing in programming. The term Model-View-Controller is
known since the beggining of Smalltalk (actually I'm not sure about an
origin of that term, but I found MVC mentioned as Smalltalk's term). So,
what is behind MVC. If you look at Swing API, you'll see at a glance
that e.g. JTable is based on another class - TableModel. TableModel
holds a data and let you manipulate that. If that data needs to be
displayed, you should construct a table with a model as just mentioned
TableModel. It's very simplified model, but your should get a clue:)

Let see some examples, so you'll get more feeling about JSP and how one
can mess it up.

1. First example where you see some JSP and HTML code in one file (very
bad design):

<html>
<body>
<table>
<%
  // Vector of Men
  Vector v = getSomeDataFromSomewhere();
  for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
    Man m = (Man)e.nextElement();
    String firstName = m.getFirstName();
    String lastName = m.getLastName();
%>
<tr>
  <td><%= firstName %></td><td><%= lastName %></td>
</tr>
<%
  }
%>
</table>
</body>
</html>

2. Second example where you see only HTML code with some new tags

<%@ taglib uri="/tags" prefix="my" %>
<html>
<body>
<table>
<my:show name="man">
<tr>
<td><jsp:getProperty name="man" property="firstName"></td>
<td><jsp:getProperty name="man" property="lastName"></td>
</tr>
</my:show>
</table>
</body>
</html>

Now, it's time to answer some questions:

1. How do you fell how much time HTML guru will have to spend to learn
1st and 2nd example ?
2. What about (cheap) HTML editors with some fancy coloring stuff ? Do
they know about JSP tags ?
3. Which parts of file can be changed and what the impact is thereafter
?
4. Do you see that 2nd example is divided, so JSP stuff is done by JSP
guru and the another by HTML guru. They can work separately. Just give
specification about new tags to HTML developer and you can change Java
code with no impact on HTML presentation.

I hope it's not too long and it's easy to read and understand:)

>
> Thx in advance
> Rakesh.

Jacek Laskowski

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to