Results 1 to 9 of 9
  1. #1
    macaso is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Lightbulb Can you help me choosing a framework?

    Hello,

    I've been working with JavaSE from 2002 to 2008, using JDBC, Swing, Xerces, JFreeReport, and mainly Java 1.4.

    Now, I'm interested in moving to the web. I tried PHP, Ruby on Rails and Grails, but I don't like dynamic languages nor weak typing variables, and I prefer Java.

    Can you recommend me a pure Java (no Scala, so Play isn't allowed here) framework to develop web applications (not simple web pages!), with good testing capabilities and, if possible, compatible with Jasper Reports? And any advice before starting web development with Java?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Can you help me choosing a framework?

    Since you're new to this start small, but I would look at JSF for the front end bits, as that's the current standard replacing JSPs.
    Behind that possibly Spring and Hibernate?

    Compatibility shouldn't be a problem.
    So long as you structure your code properly then neither will testing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Can you help me choosing a framework?

    I see you have a better answer from gimbal over on OTN...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    mesas789 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: Can you help me choosing a framework?

    Question on Can you help me choosing a framework?
    Q: can you help me choose a framework?
    A: 11/9/12 ms
    It is common knowledge that if a servlet container has been successfully started, it is "listening" on one or more ports.
    By convention (depending on how server.xml is configured), it listens on 8080 for http and 8448 or 16448 for https.

    But let's focus on two related questions:

    What happens at startup (as opposed to runtime) ?
    And how do the various frameworks e.g. Struts 1.1, Spring IOC Spring MVC complicate or enhance this functionality?

    When the container is started, one of the things that happens (assuming everything goes well) is that the container fires a ContextLoaderListener for every app whose web.xml has the following optional configuration:

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    ContextLoaderListener can be used as a "hook" to fire something at reload time.

    But wasn’t that was the original purpose of init()?


    From my myopic point of view, I can't think of any reason to use the ContextLoaderListener, except (in my case) I painted myself into a corner by using something like Struts 1.1, and thus (without realizing until it was too late to tell the PM that I goofed and I need to start over)
    relinquished control of the init() because, you know, everything in struts 1.1 goes through ActionServlet, which doesn't have an init().
    (not %100 sure I know what I’m talking about)

    But of course if I hadn't gotten drawn into the struts thing, I wouldn't have been in that mess
    i.e. I wouldn't have needed ContextLoaderListener to do what init() was designed to do;

    In other words, the frameworks probably don't buy you anything but more complexity;

    And you’ve also bought more vulnerability in the form of another configuration file (struts-config.xml in the case of struts 1.1), in the sense that when it breaks, you may have people who understand servlets reasonably well but not struts.


    In the case of Spring IOC (a later framework that I also got drawn into) you've added the problem of trying to understand IOC (inversion of control);

    In the case of Spring MVC, you've traded the complexity of struts 1.1 for something far worse (MVC replaces struts), because with MVC, you've not only relinquished control by channeling all requests to "their servlet" and added a another configuration file, but in addition, Spring MVC is more abstract in the sense that nobody "calls" the methods;
    Instead, the classes, methods, and even the method parameters are "discovered and registered"
    Don't get me wrong. Its amazing - and beautiful in a sick sort of way;

    But you don't want this to be your problem.

    To summariaze, let’s go back and let’s assume that we're not using any frameworks on top of the servlet container. That's fine. At startup time, the servlet container already has its hands full trying to parse server.xml and, if successful, loading it, then starting the process(es) e.g one process for http and one for https, then parsing and loading each application’s web.xml.
    BTW, the processes can be observed:
    $ ps -ef |grep java

    Now let's assume life isn't sufficiently complicated, so we've decided to use Struts 1.1 or Spring IOC or Spring MVC.

    That may mean we have to use the servlet container's above-mentioned ContextLoaderListener mechanism as a hook to pre-load a config file.

    There are other ways of pre-loading. Its possible to take advantage of the fact that (at least in Tomcat 6), every init() of every servlet fires at startup.
    You could even create a separate servlet for this sole purpose, which would almost make sense, since you're channeling all runtime activity through "their" servlet and don't have access to “their” init();
    So you could create a separate servlet – call it the initializing servlet - in addition to the struts org.apache.struts.action ActionServle or the spring org.springframework.web.servlet.DispatchServlet;
    So now you'd have two servlets. There's no need to map the initializing servlet, since you're only going to code the init(), and Tomcat 6 doesn't puke at reload time just
    because there's an unmapped servlet. Does anybody agree
    with my recollection that Tomcat 3,4 and 5 were not so forgiving?


    So you'd code nothing but init() in your initializing servlet, and then code a servlet tag in web.xml and not worry about coding a corresponding servlet-mapping;
    and the init() would fire at reload time and do whatever
    you coded it to do – load a context in this case;

    But using the ContextLoaderListener is cleaner. You don't need a separate servlet();
    For either Spring IOC or Spring MVC, you just need something like the following in your web.xml (Spring IOC by default looks for a file called applicationContext.xml, in which case the contex-param is superfluous):



    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext.xml,
    /WEB-INF/applicationContext-security.xml
    </param-value>
    </context-param>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    By the way, in the case of Spring IOC, regardless of how you loaded the
    applicationContext.xml (or a different name if you chose not to use the default name), you must then manually retrieve the context in your method, or possibly your class could extend a class that retrieves the context behind the curtains e.g. you DAO domain classes might extend HibernateDaoSupport and might let HibernateDaoSupport handle retrieving the spring context and then you might call inherited (from HibernateDaoSupport) methods e.g.:

    ServletContext ctx = getContext(request);
    getHibernateTemplate().saveOrUpdate(city);

    For Spring MVC, the context-param would be more complicated (see spitter-web example in Spring in Action Third Edition);

    But staying with Spring IOC, the config file would consist of something like a sessionFactory and a dataSource and one or more DAO beans.

    For Spring MVC, as mentioned above, the classes, methods, and method parameters are discovered by Spring MVC (using annotations in the case of spitter-web in Spring in Action Third Edition)

    But regardless of whether you’re using a framework, the underlying servlet container works the same e.g.the servlet container only loads server.xml at startup, and the individual web.xml (and any additional framework configs) only get loaded at reload. And startup means restarting the entire container,as in firing the bin/shutdown.sh and then bin/startup.sh script. This is drastic, since it stops everything running in the container. Reload is less drastic as it only reloads and presumably won't crash the container if the reload fails; Reload can be done from the http://localhost:8080/manager/html ;

    So a restart obviously (1) restarts the whole container, then if successful (2) attempts to reload every app.
    And hopefully, failure on any individual reload (2) doesn't cause the whole server to fail.



    And if the servlet container cannot parse and load an individual application’s web.xml and/or any framework configs built on top of web.xml, that application reload will fail, but hopefully this will not impact the server or the other spps.

    So obviously the various optional frameworks e.g. Struts 1.1, Spring IOC, Spring MVC, Hibernate, iBATIS, WebWork, Tapestry, Velocity etc. make life more interesting and more fragile and of course increase your vulnerability.

    But inversion of control (e.g Spring IOC) may be intellectually irresistible, so you might want to do it just for the challenge;

    For examples of an applicationContext.xml with mapped hibernate and applicationContext.xml with annotated hibernate
    respectively:

    $ ssh user2@50.56.196.180 (password is user2)
    $ cd /root/projects/SpringServlet03
    $ find . |grep hbm.xml

    $ cd /root/projects/SpringServletAn
    $ vi src/com/sweeney/example/domain/City.java

    Some frameworks can be used together e.g.
    But you have to choose between Struts 1,1 and Spring MVC, since Spring MVC replaces Struts 1.1 ;
    Another option is Struts 2 (interestingly an offshoot of WebWork, not Struts 1.1 - I haven’t encountered it in the real world);

    NOTE: from here on out, I have no idea what I'm talking about

    see projects/spitter-web in the download for Spring in Action Third Edition for an example of Spring MVC, which is suspect for several reasons

    e. g. the WEB-INF is under src, a strong indication the example was not tested. Also the downloaded example doesn't bear much relation to the book.

    Cheers.
    Last edited by mesas789; 11-10-2012 at 06:06 PM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Can you help me choosing a framework?

    I think this is the first time I've heard all of those frameworks described as fragile.
    In my experience they provide a more solid app at the end. Some handle this better than others, of course.
    IOC is an example of this, if nothing else than ensuring you have testable code, just from the nature of how the various parts are declared.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    mesas789 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: Can you help me choosing a framework?

    Tolls -
    Thanks for replying.
    Not sure I know what I'm talking about.
    I think its important to realize four things about IOC:

    1) The subject of IOC doesn't necessarily have any relation to the subject of web applications.

    2) IOC and hibernate were disparate contemporaneous technologies;

    3) IOC and annotations were also disparate and contemporaneous; My recollection is that early editions of "Spring in Action" were written before annotations were invented;

    4) IOC doesn’t have anything to do with Spring MVC;
    I think its best to stop people (at the risk of being abrupt) when they say "Spring" and ask them what they mean.

    Happy Debugging!
    Last edited by mesas789; 11-15-2012 at 07:45 PM.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Can you help me choosing a framework?

    Well, you brought up IOC, I was merely pointing out one of the advantages.

    I'm not sure what you are getting at with your 4 points.
    Anyone who knows the history of Java knows that Spring <> Hibernate. Rod Johnson <> Gavin King...:)
    They also know that Spring <> annotations. Rod Johnson <> the Sun development team. Spring predates annotations by a couple of years.

    And I would question point (4) if only because IOC is fairly central to Spring.

    So, really, what are you trying to say?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    mesas789 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: Can you help me choosing a framework?

    Well since you’re pinning me down, I would opine that you don’t have to do annotations just because its new and radical.
    I’ve met brilliant programmers who had nothing polite to say about annotations.

    As far as IOC, it reminds me of what somebody said about saxophonist John Coltrane: “I don’t like it, but its pretty hard to ignore”

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Can you help me choosing a framework?

    There's a reason IOC is popular, because it works.

    And I've never written an annotation in my life.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Program about choosing category
    By moony in forum New To Java
    Replies: 16
    Last Post: 06-04-2012, 07:17 PM
  2. Choosing db option
    By Levian in forum JDBC
    Replies: 6
    Last Post: 03-17-2012, 03:21 AM
  3. Need guidance in choosing the appropriate technology
    By mstaszew in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 10-20-2011, 06:25 AM
  4. Choosing the best desktop application framework
    By hariharansrc in forum Advanced Java
    Replies: 0
    Last Post: 08-22-2011, 03:47 PM
  5. Choosing a degree concentration
    By xcallmejudasx in forum Jobs Discussion
    Replies: 11
    Last Post: 08-14-2009, 12:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •