Matt RaibleMatt Raible is a writer with a passion for software. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.
You searched this site for "servlet". 226 entries found.

You can also try this same search on Google.

Hibernate PlugIn for Struts

I don't know that there's a need for a Hibernate PlugIn for Struts, but I wrote one today just for kicks. Pretty simple stuff that only requires you to have hibernate.cfg.xml in your WEB-INF/classes directory, and to add the following to your struts-config.xml.

<plug-in className="org.appfuse.webapp.util.HibernatePlugIn"/>

Then create the file org.appfuse.webapp.util.HibernatePlugIn as follows:

public class HibernatePlugIn implements PlugIn {
    //~ Instance fields ========================================================

    private Log log = LogFactory.getLog(HibernatePlugIn.class);

    //~ Methods ================================================================

    public void init(ActionServlet servlet, ModuleConfig config)
    throws ServletException {
        try {
            SessionFactory sf =
                new Configuration().configure().buildSessionFactory();

            if (log.isDebugEnabled()) {
                log.debug("Hibernate configuration completed.");
            }
        } catch (HibernateException h) {
            log.fatal("Error configuring Hibernate!", h);
        }
    }

    public void destroy() {}
}

This doesn't seem to have any advantages over using a StartupListener, but it would be pretty sweet if it was included with Struts (or Hibernate), so you could simply put it in struts-config.xml and be done with it.

Posted in Java at May 31 2003, 11:31:41 AM MDT 2 Comments

Running a process from a servlet

Note to self: This may help you in running moblogger from a servlet:

Process p = Runtime.getRuntime().exec("/bin/chmod 700 /path/to/myfile");

I found this nugget on the tomcat-user mailing list - and I'm assuming it can be used to run any command-line process.

Posted in Java at May 05 2003, 05:10:11 PM MDT 2 Comments

Use XForms now with XMLForm

Remember XForms (the next generation of HTML Forms)? How about XMLForm? From their homepage:

This is a standalone servlet toolkit inspired by Apache Struts / JavaServer Faces and W3C XForms. The toolkit is derived from Apache Cocoon and a best effort will be made to maintain the features in sync with the Cocoon module.

For an introduction to the concepts, see: XML Forms, Web Services and Apache Cocoon

XMLForm uses W3C XForms based markup and automated server-side binding to JavaBeans, XML/DOM, JDOM and DynaBeans data models. It also allows easy deployment of REST style Web Services, with maximum code reuse between human facing and machine interfaces.

Wow! Sounds very cool. Thanks to Vic for the link.

Posted in Java at Apr 05 2003, 11:19:01 AM MST Add a Comment

OSCache doesn't play nicely with Tiles

I was hoping to use OSCache to cache my JSP pages to overcome my 15-seconds-to-load performance issue. I was hoping to simply place <cache:cache> tags around my entire Tile's baseLayout.jsp. However, I was disappointed to find that this did not work. I get this nice error message:

Can't insert page '/common/header.jsp' : Illegal to flush within a custom tag 

I even tried it just surrounding my 200+ row table of indexed properties, but no dice, same error. Oh well, onto caching with Hibernate's JCS support.

Posted in Java at Mar 27 2003, 09:19:45 AM MST 2 Comments

Tomcat Upgrade (to 4.1.24) Successful!

I spent the last 5 minutes upgrading this site to Tomcat 4.1.24. It was pretty simple; here's what I did:

  • Copied conf/tomcat-users.xml and conf/server.xml from old version to new version.
  • Copied JDBC Drivers from common/lib.
  • Moved relevant apps from webapps/ to new version.

The manager application looks like it has been improved to allow for easier deployment. It now offers you more, clearer choices and you don't have to remember the cryptic syntax for deploying a .war file. Now it's just browse and submit. Let me know if you see any issues.

Update: I still can't get the "admin" application to work, but I never use it, so not a big deal. It hasn't work on past versions of Tomcat either. Currently, it gives me the following error:

HTTP Status 503 - Servlet action is currently unavailable

Posted in Java at Mar 22 2003, 08:46:19 PM MST 3 Comments

J2EE 1.4 Installs just fine on OS X

I downloaded the Linux version of the J2EE 1.4 Beta today to install on OS X. I found that it installed flawlessly with the following nice little message:

[minime:~/Desktop] matt% ./j2sdkee-1_4-beta-linux.sh                            
Using /var/tmp as temporary directory...                                        
Searching for Java(TM) 2 Platform, Standard Edition...                          
Initializing InstallShield Wizard...                                            
running on mac

Cool! Now to see if I can get the Adventure Builder reference application running on the Mac. I also found this interesting article on the new JSP and servlet capabilities in J2EE 1.4.

Posted in Java at Mar 20 2003, 05:04:23 PM MST Add a Comment

Struts Training: Week 3

I just signed in for 3rd week here in Struts Training. I'm coming to you live from Chelan, WA. So on with what Ted has to say.

Ted's talking about persistence in Struts: Transaction Script vs. Domain Model.

Transaction Script - organizes business logic by procedure. Great choice for small applications with simple logic. For example, online auction, public search engine or an address book.

Domain Model - an object model of the domain. Has a rich variety of objects that incorporate both data and behavior. Ted mentions that the Domain Model is better for larger applications. For example, managing inventory for an online auction might require using the domain model.

What Ted is doing is using the Domain Model to separate Struts from his Actions - so that he passes around a DomainRequest, DomainResponse, and gets his form from a factory. To me, this looks like a good way to make your Struts layer a lot more complicated! ;-) At the same time, Ted is getting this information from Martin Fowler's Patterns (in Enterprise Architecture, ISBN 0321127420) book, so maybe I should move to the domain model. Naahh, I think I'll keep using the Transaction Script method - it's probably easier for folks to learn and would definitely be easier for rookies to maintain.

Onto Hibernate and how it works:

- POJO beans, encourages fine-grained
- Utilizes "persistence by descriptor"
- Provides DBA-friendly text queries
- Plays well with others
- Buffet-style implementation

IMO, if you're not using Hibernate, you should know why. If you're starting a new project, it's worth looking at. If you're using it, but not using XDoclet - you should be. XDoclet is the best way to avoid DD Hell (quoted from Erik Hatcher).

I didn't know that Hibernate supported a version - did you? Apparently you can specify that a property is a version and Hibernate will use it as you'd expect. Don't see that I have a need for that, but possibly. Would a struts-resume user ever want to keep old versions of their resume? I like to keep old versions of mine, but I have to admit, I never look at them again.

<version name="version" />

Ted just touched on how Hibernate can generate your database schema for you. This is a very powerful feature IMO - especially with struts-resume. It makes it nice for an example app. For instance, with struts-resume, you can run "ant setup-db" and it'll drop tables and re-create your db schema for you.

A student asks about the bottom-up approach - what if you already have a database. My advice? Try looking at Middlegen, its Hibernate Plugin in designed to create an XDoclet-enabled POJO from a database schema. There's also the Reverse Schema Generator that is included with Hibernate. I've used this one and it works great. I've never used Middlegen, but I should be considering that I tag the generated POJO up with XDoclet tags.

Interesting: Ted just mentioned that Gavin (Hibernate's Lead Developer) is working on a book for Manning. It is on Object Relational persistence and it uses Hibernate for its example apps. Erik Hatcher, at his preso on Wednesday, also mentioned that an XDoclet in Action book will be published soon by Manning. He even showed us the book's cover - so I'm assuming it will be published soon.

Hibernate's Fashionable Friends: XDoclet, Commons Logging, Commons DBCP, DynaBeans and Turbine Caching.

To learn more about this Hibernate, checkout:

· AgileData Website (Scott Ambler)
· Hibernate Homepage
· Struts Application Site (Hibernate example and Struts Resume both use Hibernate with Struts)

Vic still likes RowSets and SQL better. I'm guessing this is because he's a SQL expert. The nice thing about Hibernate is that it's query language (HQL) is very much like SQL and allows you to do complex joins. At least, to my knowledge, I've never done any fancy joins in the HQL, just in the mapping (*.hbm.xml) files.

Quote from Ted: This is the year of JUnit books. Watch for them this summer..

Now Ted is covering StrutsTestCase, a JUnit extension that hooks into Struts and Cactus. IMO, it's an awesome way to test Struts Actions - even easier than testing a servlet with Cactus.

Another book: JUnit in Action (Manning) by Vincent Massol and Ted. To be published this summer. Vincent is the lead developer on Cactus, so I expect this to be a great book. Right now, I wish I had written my first book for Manning rather than Wrox. :-(

The one bad part about today's session is that I had to use a calling card to dial in and at $0.35/minute, I'm up to about $25! I should probably sign off soon and save some cash...

Tapestry - are you using it? A student asks about it and Ted mentions that he views it as a presentation framework like Velocity. I've heard lots of good things about it, but have never used it. Ted admits that he uses Velocity and gave up on using JSPs a while ago.

Good stuff - thanks Ted, I'm signing off (the QA session is still in progress).

Posted in Java at Mar 15 2003, 08:37:28 AM MST 1 Comment

Denver JUG Review

Last night's meeting was great. The first presentation on TINI was very cool and showed how you could telnet/ftp into this SIM (RAM-style) device and run Java on it. Granted, it only supports JDK 1.1 and lacks some cool stuff, but it can run a servlet engine and even serve up web pages through a servlet. This was all designed to demonstrate how Java can run on embedded devices. The speaker thought that embedded devices would be the next big thing for Java. IMO, he has to - especially since he seems to have dedicated a lot of work to learning about it. In reality, I hope it is the next big thing, Java (and our job market) could use a real boost.

The second preso was by our good friend Erik Hatcher. It was the first time I've met Erik in person, so that was definitely the highlight of the night. He's a very down-to-earth fellow and gave a great presentation. If I didn't learn so much about XDoclet in the past couple of months, I would've been wowed. I did learn that I should replace my // TODO: comments with @todo in the JavaDoc so I can use XDoclet to generate a JavaDoc-like website of my todo list. I'm definitely looking forward to the next time he speaks at the NoFluff Symposium.

Moblogging went fairly well as you can tell from the pictures. These photos look pretty awful on the camera, but turned out decent on this site. I'm heading off on a trip to Chelan, Washington this weekend and will hopefully snap some more pics (pending connectivity).

Posted in Java at Mar 13 2003, 07:41:01 AM MST Add a Comment

Servlet 2.4 Specification

Damn, according to The Server-Side, the new XSD syntax for a web application's deployment descriptor (web.xml) has been removed. Or at least that's how I first read it. That would suck, only because it's one of the things I noted as a difference between 2.3 and 2.4. Where did I note it - in the chapters I wrote for Wrox. Doh - get those chapters back from the printing presses!

Posted in Java at Mar 09 2003, 08:44:10 PM MST Add a Comment

Struts Training: Week 2

I'm planning on attending today's Struts training and will be reporting here again. I got up at 6, hoping to do the labs and discovered the first step was downloading the latest Basic Portal setup. Since it's 200 MB, I've been dicking around for the last hour and a half, waiting for it to download. Yikes - I thought struts-resume was bad at 10.5 MB! I guess the difference is that it includes JRockit, Mozilla, OpenOffice, Vim, Ant, Eclipse, JMeter, Jikes, PostgreSQL and Resin.

Today's session seems to be covering databases, SQL and database performance. Vic mentions that 90% of performance is in the data model design. If you can fit your database on a laptop, then performance will probably not be an issue. I agree with this. I did the first lab during the first half-hour of the preso. Pretty simple stuff: creating HTML files and accessing them through a browser. This is probably a good lab to get everyone going and stuff installed. Also proves that Resin is running. Of course, it took me two hours to complete this lab, including the download, so I guess it's not that short!

Commons SQL is a new version of Torque (a manual persistence layer). Vic uses RowSets a lot, has one site with 40,000 concurrent Struts users with sub-second response times. He attributes this to rowsets. He says, "To create high-scalable applications, you need to know SQL and use things like RowSet, Ibatis.com, Commons SQL and Scaffolding." I tend to disagree - I think that EJBs (and possibly Hibernate) are your best bet for highly scalable application (i.e. 10,000+ hits per second). If your EJBs are slow, it's probably your code or your appserver. Try EJBs on JBoss and I'm betting you will be pleased. Then again, I've never created a highly-scalable application, and Vic has, so I'm not much of an authority. He, he - he mentions that Castor has lost a lot of mindshare; "Great for development, but not very scalable in production." So true - or at least Roller seems to prove this. From the folks he's talked to, Vic says that TopLink has a horrible reputation.

Hmmmm, interesting. Vic puts all the database connections and CRUD in his ValidatorForms. This is not saying that his bean matches his database tables. I don't know that I'd recommend this, but it certainly might simplify things. However, personally, I'm more comfortable with keeping my POJOs and ActionForms pretty dumb (just getters and setters). He has a DAO that handles CRUD and population of the bean. I wonder where you'd put the business rules in this implementation? In the DAO? If it's in the DAO, what if you have to write a new DAO implementation. For instance, if we used this approach on Roller, we'd have to re-write our business rules for Hibernate and Castor. Ugh.

For testing, he puts a test() method on his beans and uses a Servlet or a plain class with a main() method. Personally, I'd recommend using JUnit and JUnitDoclet (and Ant) to generate and run your unit tests. It's much easier than writing a servlet to test - and can easily separate your tests from your real code. See struts-resume for examples. I'll be releasing AppFuse in the next couple of weeks. This (hopefully) will provide a nice starting point for creating web applications. In reality, if no one uses it, I'll probably be better off (less support). It's been working great for me on my current project and has easily saved us a month of startup time. Right now, appfuse == struts-resume.

Vic mentions using a BaseAction that dispatches to the appropriate method in your subclasses. He says that the only difference between this technique and DispatchAction (or LookupDispatchAction) is you can specify a default method. Here's a tip: use the unspecified method. Here's how to make your edit() method the default:

public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
throws Exception 
{
    return edit(mapping, form, request, response);
}

Vic hints that the next iteration of Basic Portal will be written to use the iBATIS Database Layer and MySQL. Interesting, I thought iBATIS was a company, but nope: it's from the author (Clinton Begin) of JPetstore. On most days, I'd recommend Hibernate here, but I've spent the last 3 days wrestling like mad with it, so I won't. Of course, after leaving work last night, I think I might've figured out the problem. My brain is likely to blame more so than Hibernate.

Ted Husted chimed in at the end and mentioned that he is going to touch on Hibernate next week. Cool!

Posted in Java at Mar 08 2003, 08:13:11 AM MST 4 Comments