tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: JSP help: A bit off topic
Date Fri, 03 Jan 2003 19:51:00 GMT


>  myObject.getSomeString() /* This will actually contain all the code in
>  JSP, just to avoid the JSP page cluttered with Java Code */

If you expect getSomeString() to return *JSP* code (including tags and
scriptlets and all), you can't do that.  The JSP code is compiled the
first time you execute this page -- you can't create it dynamically at
runtime.

At best, you could have getSomeString() return some static HTML code and
write it to the output stream:

    <%
      out.println(myObject.getSomeString());
    %>

However, embedding *any* of this stuff is really a misuse of the
technology, because you end up intermixing business logic ("what data am
I manipulating") with presentation logic ("how do I want this data to
look") in ways that will lead you into unmaintainable spaghetti code that
is very difficult to update later.

A far better strategy is to use some sort of MVC architecture (such as
Struts, http://jakarta.apache.org/struts/) and put your business logic in
Java classes, and your presentation logic in your JSP pages or whatever.
Let your business logic deal with the *data* (getting it from the
database or whatever) and your JSP page deal with the *UI* (how it appears
to the user).

Craig


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message