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.

Turn off sessions in your JSPs

One of the tips I picked up in J2EE Design and Development was to turn off automatic session-creation in your JSPs. So I tried this today on my project, and it doesn't seem to work. Basically this involved putting the following at the top of your JSPs:

<%@ page session="false"%>

I did this by adding this to my taglibs.jsp, which is included in every other JSP - so it should affect all my JSPs and prevent a session from being created on my welcome-file - right? Not according to Tomcat's Manager application - it still increments the number of sessions as I hit the welcome page with different browsers. Am I doing something wrong?

I'd love to get this working - so sessions are only created when a user logs in. Those JSPs that need a session, I'll override the default with session="true". I often see a whole bunch of sessions on the wiki and roller apps on this site - and in reality - a session should never be created, unless I login. At least I think that's how this is designed to work...

Posted in Java at Jan 22 2004, 11:23:18 AM MST 4 Comments

Macromedia's Flex

I learned about Macromedia's Flex from the JavaLobby Newsletter this morning.

In essence, Flex is a presentation server that sits on top of a standard Java servlet container like Tomcat and provides the ability to use the Flash player and an updated scripting language to manage the client-side user interface of a web application. The Flex Runtime Services provide management of server-side security, connections to data sources, and so forth. The Flex Class Library provides support for a full set of server-side flash components that can be accessed via an XML markup language currently called "MXML" (which is going to change before the product release.) MXML contains the tags for the widgets in the Flex Class Library and allows you to express rich user interfaces succinctly.

I've always liked Flash, but I'm also a sucker for eye candy and cool-looking UIs. If Macromedia could make it possible to create flash files with a markup scripting language, like I do HTML/JavaScript for JSPs - I think they'll get a winner. If we're forced to use IDEs and other tools to drag and drop components - I won't bite. I'm too used to typing vs. point and clicking. I don't use Dreamweaver for HTML - why would I start now?

However, I do have a friend who is an awesome Flash Animator - it'd be cool to hook up with him someday to create rich web UIs. Only problem is - I think it'll be tough to find a client that prefers a flash interface over an HTML-based interface.

What would be awesome is if I could use a RenderKit from JSF to create a Flash UI. The ability to write standard HTML/CSS and have it generate a Flash UI that could do everything like a desktop app - mmmmm, sounds sweeeeettt.

Update: The Flex JSP Tag Library might be just what I was looking for. I also found an article on Providing a Flex Front-End to your Struts Applications. In my opinion, the one reason that Flex won't work is that it will cost money - all other J2EE View technologies are free. Cheap is good though - it might work if it's a mere 50 bucks.

Posted in Java at Jan 14 2004, 07:08:09 AM MST 5 Comments

AppFuse on DB2 and WebSphere

I did some trial-and-error this morning, and with the help of a lot of handy-dandy unit tests, I got [Appuse working on DB2|AppFuseOnDB2]. I learned that I need to figure out how to create a database with page size = 8 by default - anyone got a SQL script to create DB2 databases (with reasonably sized table spaces) lying around?

Next up: Getting AppFuse running on WebSphere 5.1, this should be fun. Especially considering that they only seem to support .ear files, not .war files. I've only glanced at the thing for 5 minutes - any advice/links would be awesome.

Posted in Java at Jan 12 2004, 10:23:11 AM MST 9 Comments

Should I buy a PowerBook or a PC?

I received the following e-mail from Jason Boutwell a couple of days ago (published here with his permission).

I'm in the market for a new development laptop, either a P4 or a G4. I see from some of your older blog posts that you went through the same thing last year. First you went with a P4, then ended up with a PowerBook, so you've done both.

Since we seem to have similar professional interests (jobs where you BYOL, developing J2EE apps with tools like Hibernate, Struts, XDoclet, IDEA, etc.), you seem an ideal person to ask.

It's as simple as this: you can't beat the form-factor of the PowerBook. The fact that it's so small and light really make it a killer laptop. iPhoto, iMovie and iTunes are all killer apps and make digital photography and video so much easer. However, as a development environment - it sucks. It's sooooo much slower that my Windows XP desktop (that only cost $800).

My perspective of the speed difference might not be fair though - desktops (most likely) will always be faster than laptops. However, to run "ant deploy" for AppFuse takes 23 seconds on my 2.6 GHz CPU / 1.5 GB RAM desktop and 36 seconds on the PowerBook (1.33 GHz CPU / 1 GB RAM). It is difficult for me to develop on the Mac after developing on my PC for awhile, it's just so much slower. That being said, I don't think I'd be happy with a PC laptop - they're too ugly and bulky (for the 17" models) and don't offer the slick digital hub integration that the Mac does.

Don't expect the PowerBook to be a desktop replacement. And if you've never used a Mac, prepare to be frustrated. I've been a Windows user for 10+ years and getting used to the way a Mac works is not easy. It's been most frustrating for me because I can navigate around and do stuff on Windows really fast - it's almost like second nature. On the Mac, I have to think about how to do stuff. I think that Mac or Linux users migrating to Windows would feel the same frustration.

Above all else, you need to experience a Mac first hand. Go to your local Apple Store and play around with one. Download your favorite IDE and checkout an open source project from SourceForge. Download and install Ant and try compiling the project. You're gonna love the feel of the Mac, but you might find it's a bit slower than you're used to.

The one problem with not buying a PowerBook is that you'll always long for one. ;-) Would I buy a PowerBook again? Definitely. Would I give up my Windows desktop for a Mac desktop? No. Why should I give up all my years of becoming an efficient Windows user to be a slow-ass frustrated Mac user - it just doesn't make sense.

Posted in Mac OS X at Jan 10 2004, 05:58:17 PM MST 23 Comments

The Battle of the GZip Filters

When I first added a Compression/GZip filter to AppFuse, I used the one from Roller, which I believe Lance found in this book. This has worked fairly well since I added it in July last year. When I discovered that there were issues with it on Resin, I chaulked it up as "no big deal" since I don't use Resin anyway. But yesterday, when I discovered that it stopped my apps from displaying my 403 <error-code> page, that was the last straw. I remembered seeing the "Two Servlet Filters Every Web Application Should Have" article on ONJava.com about a different implementation, so decided to download the source and try it out.

I quickly discovered that this Filter does work on Resin, so that's quite a bonus. I've had issues getting Roller to work on Resin with the Filter enabled, so I might have to replace Roller's CompressionFilter. However, I did still have to change a few things to convince this Filter to satisfy my needs.

Here are a few things I discovered about this GZIPFilter vs. Roller's CompressionFilter:

  • Don't download the GZIPFilter from the article. There is a newer version of the code. Not much has changed, save for an almost completely re-written GZipResponseStream.java file. This one supposedly does better handling of large files.
  • This Filter has the same problem I experienced with Roller's CompressionFilter: JSP pages don't finish rendering when running my Canoo WebTests. I'm assuming that this is because the buffer hasn't finished spitting out HTML. I ended up writing a new isGZIPSupported() method (in GZIPFilter.java) to do the check for GZip support. This allows my webtests to run smoothly by disabling the filter for HttpUnit.
  • This Filter shares another issue that I found in the CompressionFilter yesterday. When my webapp returns an HttpServletResponse.SC_FORBIDDEN error code (from trying to access a method that denies the users role), the Filter suppresses the error and the user is not served up the 403 error page defined in my web.xml. To fix this, I overrode sendError() in GZIPResponseWrapper.java and added a check for this error code in the getWriter() method.

Overall, I'm pleased with this code because I love the concept of GZip Filtering, and now it's not causing any conflicts in my app or targeted appservers.

GZIPFilter.isGZIPSupported(HttpServletRequest):

    private boolean isGZIPSupported(HttpServletRequest req) {
        String browserEncodings = req.getHeader("accept-encoding");
        boolean supported =
            ((browserEncodings != null&&
            (browserEncodings.indexOf("gzip"!= -1));

        String userAgent = req.getHeader("user-agent");

        if (userAgent.startsWith("httpunit")) {
            if (log.isDebugEnabled()) {
                log.debug("httpunit detected, disabling filter...");
            }

            return false;
        else {
            return supported;
        }
    }

GZIPResponseWrapper.sendError(int, java.lang.String):

    public void sendError(int error, String messagethrows IOException {
        super.sendError(error, message);
        this.error = error;

        if (log.isDebugEnabled()) {
            log.debug("sending error: " + error + " [" + message + "]");
        }
    }

GZIPResponseWrapper.getWriter():

    public PrintWriter getWriter() throws IOException {
        // If access denied, don't create new stream or write because
        // it causes the web.xml's 403 page to not render
        if (this.error == HttpServletResponse.SC_FORBIDDEN) {
            return super.getWriter();
        }

        if (writer != null) {
            return (writer);
        }

Posted in Java at Jan 09 2004, 11:30:43 AM MST 15 Comments

Running AppFuse on Resin

Want to run AppFuse on Resin? I did some research (a.k.a. banging my head against the wall) and figured out how this morning. It isn't too tough, now that I've figured out how. You can read about my journey on my wiki, or follow the following steps (for the CVS version):

  • Edit $RESIN_HOME/conf/resin.conf and add the following after the last </web-app> closing tag.
<resin:include href='appfuse.conf'/>
  • Download appfuse.conf(info) and put it in the $RESIN_HOME/conf directory.
  • Put activation.jar, mail.jar and mysql-connector-java-3.0.9-stable-bin.jar in $RESIN_HOME/lib.
  • Remove password encryption by changing the Login Servlet's encrypt-password init-param (in web.xml) to false. You can do this in the build process by changing "encrypt.password" to false in app-settings.xml. You could also do it from the command line using -Dencrypt.password=false. For testing, you will need to change a number of files that have the encrypted password. Search for "536c0b339345616c1b33caf454454d8b8a190d6c" and change it to "tomcat".
  • Remove the <filter-mapping> for CompressionFilter.
  • To enable the "Remember Me" feature, remove the <c:if test="${rememberMeEnabled}"> check in loginForm.jsp. (AppFuse 1.3-dev)

DISCLAIMER: I did not thoroughly test that everything works, I just ran through a couple of pages.

Posted in Java at Jan 04 2004, 09:47:43 AM MST

Roller Tips: Titles as Permalinks and Category Display

A few more tips for your Roller blog. You can edit your "_day" template to make your titles permalinks. I just added this feature to this site - try it now by clicking on this title for any post. To enable this feature, simply wrap your $entry.title element with a permalink URL. For example, change <b>$entry.title</b> to the following:

<a href="$baseURL/page/$userName?anchor=$entry.anchor" 
   style="font-style: bold; color: black">$entry.title</a>

Adjust the style as appropriate for your theme. The second tip is to add the ability for users to see the category you've posted to. Simply add the following under the $entry.title entry to display the category name in the top right corner of the post:

<span class="dateStamp" style="float: right">
    Category: $entry.category.name</span>

Again, the CSS for the span may depend on your theme. Lastly, if you click on a permalink for your blog and you're not routed to the specific entry you expect, for the love of God add the following before your $entry.title.

<a name="$entry.anchor" id="$entry.anchor"></a>

Posted in Roller at Dec 31 2003, 02:57:34 PM MST 7 Comments

AppFuse 1.2 Released!

This is primarily a bug fix release. Here are the details from the release notes:

  • Backed out Http Post for Remember Me. It was not redirecting user to the page they originally requested. Using reponse.sendRedirect does send the user to the proper location. Turned on password encryption (SHA) to protect any passwords that end up in log files. Turned off encryption in Tomcat.
  • Changed configuration parameters in servlet context to be in a hashmap.
  • Improvements to StrutsGen tool to generate list screen as well and to fill in more missing elements.
  • Changed to close Hibernate session when object not found in BaseDAOHibernate.
  • Fixed bug in UserAction.save: when creating a new user, role defaults to "tomcat" regardless of what the user chooses.
  • Dependent packages upgraded:
    • Hibernate 2.1.1
    • Struts Menu 2.1
    • WebTest Build 379

Download (~11.9 MB for src, ~4.3 MB for bin) or View Release Notes.

For more information on AppFuse, check out the AppFuse Wiki Page or FAQ.

Posted in Java at Dec 21 2003, 08:07:27 AM MST

Interested in Java ISP Options

I'm not exactly looking for a new ISP, but I am interested in exploring my options. I'm currently averaging about 10 GB of bandwidth usage per month, and it's unlikely to go down. I only pay around $50/month, so it's not bad, but I wouldn't mind some more RAM. I don't want to administer the server per say - I'd like backups and e-mail setup/config done for me. I don't think I want my own server b/c I don't want to be a sysadmin - I only want to worry about the Java server setup. Below is my ideal setup - please let me know if you think there's other things I should be looking for.

  • Linux
  • 512 MB RAM
  • 1 GB disk space
  • A Fat Pipe (100 MB+)
  • 25-50 GB traffic
  • Tomcat or Resin (Servlet 2.3 and JSP 1.2 at a minimum)
  • MySQL databases (2-5)

Posted in Java at Dec 18 2003, 02:09:30 PM MST 12 Comments

Struts 2.0

There's a flurry of e-mails about Struts 2.0 dancing around on the Struts Developers Mailing List. Looking at the Overview or the ReadMe, you can see that there's some major (revolutionary) changes being discussed. The Struts Bandwagon is alive and well. The proposal is called Jericho (since it tries to tear-down the walls within the Struts architecture) and proposes to open-up Struts by:

  • Declaring interfaces for all core components.
  • Providing working base implementations for all core components.
  • Encapsulating alll path references within "Location" objects (fka ActionForwards) and referring only to Locations from all other objects.
  • Providing additional extension points from core components so that the "Inversion of Control" pattern is fully realized. (e.g., a populate method for the FormHandler.)
  • Providing "POJO" signatures that encapsulate servlet/portlet behavior so that applications can be freed of servlet/portlet semantics, if so desired. This strategy would also be applied to optional packages like Validator and Tiles.
  • Retain optional access to servlet/portlet objects so that applications can be free to do whatever they need to do.

Also under consideration - adding Struts Menu to the core. Good stuff my friends, good stuff.

Also noticed on the mailing list - Tomcat is not the Servlet/JSP reference implementation (news to me):

There is a (mis)conception, for example, that Tomcat is the RI for the servlet and JSP APIs. That is not the case -- the official RI is the "J2EE SDK" available at http://java.sun.com/j2ee/1.4/download-dr.html. It happens to *include* code from Tomcat, but this is the real RI.

Posted in Java at Dec 18 2003, 11:24:32 AM MST 4 Comments