#1
  1. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62

    A Jakarta overview, please


    Hi all,

    I managed to get Apache Jakarta/Tomcat installed on my FreeBSD server, running servlets and JSP. I just have a few very general questions for those of you with server-side Java experience.

    I know the general concepts behind Java, but I am just bewilderd by all the different choices available at http://jakarta.apache.org/

    I mean, we go from "Alexandria" to "ORO" to "struts" to "Velocity", etc... I am fairly certain that Java will play a large part in the future of some of the projects I am developing, and I'm trying to decide where to spend my time.

    Here is where I am coming from: I have been doing server-side development for 3 years with PHP, and to a lesser extent with Perl. I am also familiar with the object-oriented nature of Javascript, much of which was derived from Java. I am at the point now where I need to start thinking about enterprise-level systems, and n-tier approaches to web applications.

    I am very happy with PHP and will continue to use it in just about every project I produce, but I want to start "hooking up" the smaller applications and libraries I produce into larger interfaces (in Java), as well as use some of the more advanced aspects of Java for network programming, and distributed resources. I won't necessarily be communicating to Java only through PHP, though; I still will probably need some JSP or Servlet front-end stuff also.

    In other words, Java will become intertwined with a lot of what I am doing, but leaning more toward the middle or back-end, with PHP more toward the front end.

    Now, having said that mouthfull, I am looking for a good place to start: I want to make the best use of Apache's Jakarta resources.

    1. Which of the many Jakarta technologies is most central, and of most likely benefit to what I intend?

    2. Given my background, where would I find the easiest way to get started learning server-side Java?

    3. Can anyone give me some links to good tutorials and script repositories for the kind of programming I mention above?

    Thanks for any and all help and discussion prompted by these questions .
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    0
    Rep Power
    0
    Jakarta Tomcat is, IMHO, the most central application on the jakarta site. I've been working fairly heavily with JSP/Servlets for the last year and that's what I've been using most. Basically, tomcat is practically required software for JSP authors.
    After Tomcat take a look at 'Ant', *make without the wrinkles*
    It's a really sweet build tool for Java. I've been meaning to take a look at the taglibs, they're probably really handy, but I just write my own tags on an as-needed basis so I've got my own fairly hefty library so I never bothered.

    The best way for you to learn JSP would be to practice. Maybe re-write a few of your previous applications in JSP. Make mistakes. Fix em. Re-design the whole thing and you'll come out with a better understanding than anyone that's just read the book.

    You seem to be fairly familiar with Java and programming in general so just go for it, install Tomcat and fiddle around til you get the hang of it. It's not really that difficult at all.

    Good Luck!
  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Thanks for the response. I will definitely be working through some tutorials and scripts, etc... I'm just trying to get a feel for the big picture here. With Java, there are so many layers, it sometimes boggles the mind.

    As I understand it, we have the base Java layer (JRE?) which is the execution engine, from Sun. Then we have the JDK, which provides the ability to compile java .jar files, and interface with different APIs. Then we have bewildering list of base APIs from Sun for various areas, such as JSP, Servlets, client-side applets, and a whole list of other applications, including wireless devices, etc... Then... we have the incredible explosion of third-party classes and APIs (such as Jakarta), and then the sub-libraries of each of those (such as Tomcat, or Ant). So, after we have digested enough of this to know where we want to start, we can actually get down to trying to configure our system, after which we can finally ... gasp... start programming . Am I missing any pieces in between?

    So any way, I am trying to jump to some of the programming, but am still digesting all the available applications and libraries. For example, I have heard that Tomcat is slow, and that if I want a serious Java webserver, I should check out Resin. I am open to all suggestions at this point. Anyone have any pros/cons about Resin, or any other Java webserver platform?

    I tend to favor the Jakarta project simply because I love Apache, and the fact that it is open source. It seems to me that even though it may not be the fastest, it has a very broad spectrum of applications, which allows incredible flexibility. It looks to me like they are coding for the future, rather than for right now, so they are focusing on getting a foothold in as many areas of Java web applications as possible, and concentrating on functionality and stability first, leaving performance to come later. Resin, on the other hand, has taken a focused and reasonable "today" approach, and built something quite nice, even though it is not licensed as freely. (I don't mind paying for worthwhile software)

    On to a more specific search: I am trying to test my JDBC connections to MySQL and PostgreSQL. Anyone know of a Java web-based database admin kit, similar to phpMyAdmin for PHP? I would like something like this simply as a way to make sure I have averything functioning right, and to test creating and manipulating a few databases through Java.
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14

    Talking Dont Choke on the APIs


    Dont worry about all the API's Rick........take them as you need them (Even the core API)........Nobody in there right mind (no comments here....... ) can or trys to digest it all at one time. I learned by going to the API when I needed it & then once & a while I would browse thru to see what other neat stuff was there...........think of it a one hell of an encylopedia......And call it "How do I do that again?"
  8. #5
  9. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    hehe... If we were in our right minds, would we be even doing this stuff in the first place?

    I'll try to take your advice, D.C.

    So, have you heard of or seen a web-based database admin kit using JSP/Servlets? If there isn't one, then I guess I know what my first Java project should be (not being in my right mind, and all that...).
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14

    Havent see one yet but I was thinking about it


    I havent personally seen one yet but that doesnt mean its not out there. I was actually thinking of building one myself In my spare time.................YEAH, WHATS THAT. The comapny I host with uses phpMyAdmin for their "GUI" db interface it works but it REAL clunky........I do know much about php but it reminds me of perl....kind slow & unstable




    >>>>>>>>>>>Java Forever, MIcrosoft NEVER<<<<<<<<<<<
  12. #7
  13. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Ouch. I have to take issue with you about PHP. It's much faster than Perl, if it's run as an Apache module. Perl only approaches that speed when you compile Apache's mod_perl module. I have been working with PHP for almost 4 years now, and don't regret it a bit. If your web host's running of PHP seems slow, then that's because they haven't configured it right, or they are running it as a CGI, or the server is way underpowered. I also have never thought of Perl itself as unstable. It's a very mature language. Mostly the stability problems you will find are errors and inefficiencies in the script itself.

    Not that I am downplaying Java at all, mind you. For enterprise solutions, Java can do some amazing things. But I have done some serious web-based applications in PHP and Perl, with no stability or performance problems at all.

    Which version of phpMyAdmin are you talking about?. I don't find anything clunky about it (latest version) at all. (Simple, yes) It's much better than MySQL's own C++ GUI for win-32/X-win. And have you seen any of the other web-based database admin kits? Egad, talk about ugly.

    I am coming from the "other side", I guess. It seems that people who haven't spent much time with good scripting languages don't appreciate their real capability. Perl is absolutely amazing, if you actually learn how it works. If you are ever wondering, is a certain thing possible, when manipulating text or data, Perl can do it, and with probably far less lines of code than C, C++, Java. Of course Perl will not often match the raw speed of a compiled language, but what you lose in speed you make up for in flexibility.

    The real reason many programmers think of Perl as slow and unstable is more a result of old-fashioned webserver CGI protocol, which spawns a new process for every request, thus making scaleability pretty much a bad joke. But anyone who seriously uses Perl for web-based apps uses mod_perl, which is a whole different ball game. Slashdot seems to scale quite well, using mod_perl.

    But having explored quite deeply into what can be done with PHP and Perl, I am trying to understand and evaluate the benefits of Java. My feeling is that I will be using Java for some of the more serious stuff, but I will always stick with PHP for some things, and quite often I will use a combination of the two.

    For a rousing discussion on these things, see "PHP is not an enterprise solution"

    But, enough jabbering. Why don't we have some fun? Let's compare some code examples on what it would take to do certain tasks, in PHP and Java, and we'll each learn something. Sound good?
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14

    Talking Sounds Like Fighting words???????


    Just kidding there. My only experience with php has been using programs such as this. I will say though that this BB has crashed on me several times as well as others I have used. The phpMyAdmin is a great program & saves many many hours of ungodly telnet hell.....I just think there is a better way & yes I intend to try it down the road.

    As far a perl goes, been there, used it got the proverbial T-shirt & although it is an amazing language & yes very very flexible you must admit that in this day & age of monster server side programs perl just doesnt cut the mustard like it used to.

    With the complexity of todays web apps the "free-lance" flexibility of perl is a tad dangerous. I love perl for the fact that there really arent any rules, so to speak, but as this whole picture becomes increasingly complex rules are going to be very very important.

    AM I BIASED? , yes, very much so. I see the possibilities of Java .....freaking endless. There are also those that bitch that it takes 20 lines of code in Java to do what other languages can do in 5....sometimes true, but the stability, security & object oriented nature of Java outweights any code complaints.... Hey it was so good Microsoft stole it, changed a few variable names & repackaged it as C#..............Do I hate Microsoft.......NAH!!!!!!

    I really didnt mean to take exception with any other language, they all have there purposes & places. But when I look down the road to what will be needed to handle webapps 2, 4 or 10 years down the road i have a hard time seeing anything but full object oriented, safe, secure & stable code. But that will remain to be seen.......

    Id love to trade some code off & see what it takes to do things. I am somewhat limited in my time right now but it could be a lot of fun & possibly educational for everyone here.

    BTW......did you get the APIs I sent? I never heard back from you.....

    >>>>>>>>>>>>>RESISTANCE IS FUTILE<<<<<<<<<<<<<<<<

    >>>>>>>>>>>>YOU WILL BE ASSIMILATED<<<<<<<<<<<<<<<
  16. #9
  17. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    True, true, the whole "no-rules" thing in Perl is a problem for enterprise apps. Of course, some of this depends on the self-discipline of the crew involved in a project. Wall Street still uses Perl quite heavily, according to Tim O'reilly. Actually, It looks like Perl 6 is going to resemble Java in more than a few ways. And I hope I didn't seem too zealous in my defense of PHP and Perl. The web has enough software zealots already.

    I think PHP kind of treads a middle ground between the freedom of Perl and the structured approach of Java. I tend to like the freedom, because I enjoy doing the nuts-n-bolts stuff, rather than sifting through existing APIs. but I also see that one way or another, the future of web apps will be intertwined with Java. Which is just fine with me. Better Java than some Micros#ft concoction.

    Yes, microsoft stole Java for C#, just like it stole the Mac GUI, and the TCP/IP network stack from my favorite OS (FreeBSD), and the list goes on and on. Actually they didn't "steal" anything from FreeBSD, because the FreeBSD source is openly available to anyone, no strings attached.

    By the way... no, sadly the API's didn't make it through. Sorry to take up two hours of your dial-up time for that. I'm assuming there is a location somewhere to download them?

    Trading code: let's start with something simple. How about a standard SELECT query from a MySQL table, to be displayed in an HTML table? (I'll use a few of my favorite shortcuts too.)

    PHP Code:
    <?php
    //include file: config.php
    //assume that my db connection values are in a central
    //include file, using named constants, rather than standard vars.
    //this makes them automatically global, and unchangeable

    define ("DBHOST","localhost");
    define ("DBUSER","username");
    define ("DBPASS","password");
    define ("DBNAME","databasename");
    ?>

    <?php
    //main file
    require("config.php");
    mysql_connect(DBHOSTDBUSERDBPASS);
    mysql_select_db(DBNAME) or die(mysql_error());

    $query "SELECT CONCAT_WS('</td><td>',firstname,lastname,email,phone) as combined FROM users";

    /*CONCAT_WS means concatenate with separator. I basically am
     returning only ONE column from my query, called "combined" and
     every row of that column has the full HTML string to go inside a 
     table row
    */

    ?><table><?php
     $result
    =mysql_query($query);
      while(
    $row mysql_fetch_array($result))
      {
      
    ?><tr><td><?php
         
    echo $row[combined];
      
    ?></td></tr><?php
      
    }
    ?></table>
    This will output an HTML table with all the users in the "users" table. The neat thing about doing it this way, is, if my query changes, I don't have to change anything else in my code, because the variable $row[combined] contains all my HTML column information. I can place it in any <table> container I want to and just loop through the array. Now, I know this is fairly low-level, but it is very easy to turn this into a function or a class, which just returns the HTML table rows in an array, to be used anywhere.

    So, what's your favorite way to do this in JSP?
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14

    Heres the same in a servlet


    Here is the same exact code done in servlet form....

    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import com.caucho.sql.*;

    public class Sample extends HttpServlet {

    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{

    Statement stmt = null;
    Connection conn = null;

    try {
    /*Connection pool class for resin (com.caucho.sql) Pooling is
    the prefered & smart way to handle db connections Its much
    easier on the server*/

    DBPool pool = DBPool.getPool("Connection_Pool");
    conn = pool.getConnection();
    stmt = conn.createStatement();

    /*Note: connection info (db_username, ad_paddword,
    db_name etc) are stored in the servlet engine config file so you
    dont have to worry about whos trying to get at them*/


    /*set up what kind of content you are sending out (in this case
    plain old HTML*/

    res.setContentType ("text/html");
    PrintWriter out = res.getWriter();

    String query = "SELECT CONCAT_WS('</td><td>',firstname,lastname,email,phone) as combined FROM users";

    ResultSet rs = stmt.executeQuery(query);
    processResultSet(out, rs);

    if (stmt != null) {
    stmt.close ();
    }
    if (conn != null) {
    conn.close();
    }
    }
    catch (SQLException sqle) {
    System.err.println(sqle.getMessage());
    System.out.println ("SQL Exception in doPost - log in servlet");
    }
    }

    public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    doPost(req, res);
    }

    private void processResultSet (PrintWriter out, ResultSet rs) throws SQLException{

    out.println("<TABLE>");
    out.println("<TR>");

    /*loop thru rows of info returned from db*/

    while (rs.next()) {
    String combined = rs.getString(1);
    out.println(combined);
    out.println("</TR><TR>");
    }

    out.println("</TABLE>");
    rs.close();
    out.close();
    }

    };

    Of course the database stuff could have been done in a prepared statement.
    If connection pooling wasnt being used it adds a little to the code, that would look of like this:

    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql://[db_host]/[db_name]?user=[db_user]&password=[db_password]");
    stmt = conn.createStatement();

    You would also have to catch several other possible exceptions or at least declare them as being thrown (better to catch & see whats going on than throw them away!)
    They would be:

    catch (InstantiationException ie) {
    System.err.println(ie.getMessage() + "\n");
    ie.printStackTrace();
    System.out.println("Instantiation Exception in Sample.java");
    }
    catch (ClassNotFoundException cnfe) {
    System.err.println(cnfe.getMessage() + "\n");
    cnfe.printStackTrace();
    System.out.println("Class Not Found Exception in Sample.java");
    }
    catch (IllegalAccessException iae) {
    System.err.println(iae.getMessage() + "\n");
    iae.printStackTrace();
    System.out.println("IllegalAccess Exception in Sample.java");
    }
  20. #11
  21. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Very cool, and enterprize-ish

    I'm going to try to duplicate this on my Tomcat install. (Resin install coming soon)

    Thanks

    More to come...
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14

    Give it a shot........thats how we learn


    Tomcat doesnt have the built in connection pooling that resin has. I actually used tomcat up until about month ago. Once you go resin, trust me you'll never go back!

    You can set up pooling in tocat via an outside class & import it. About the best one out there is DbConnectionBroker. You can find that, & some good examples at:

    http://www.javaexchange.com/

    It works almost the same except you dont hide the username & password in a config file like resin does. Thats the one great thing about doing it in resin..if by some weird fluke someone gets hold of your class files they cant decompile them (yes there are decompilers out there) & get your db information.

    The examples at javaexchange should walk you thru it rather well. One thing though....cardinal rule in Java: Always close you connection so it is returned to the pool after using it. This is a simple line of code:

    connection.close();

    Have a blast!

    >>>>>>>>>>>RESISTANCE IS FUTILE<<<<<<<<<<<<<<<<<<
    >>>>>>>>>YOU WILL BE ASSIMILATED<<<<<<<<<<<<<<<<<

IMN logo majestic logo threadwatch logo seochat tools logo