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 "java". 1,588 entries found.

You can also try this same search on Google.

HowTo: Upgrade your app to JSP 2.0

I did some more playing with Tomcat 5.0.4 today - and converted appfuse to a JSP 2.0 application. After accomplishing this task, I created a "jsp-2" task that can (optionally) be run at build time, and whalla, you've got a Servlet 2.4/JSP 2.0 application. I learned a number of things in the process.

1. The expression language in JSP 2.0 replaces in JSTL is <c:out>, that's it. I was under the impression that I could use <c:if> or <c:forEach> tags without declaring the tag library URI, etc. I was wrong, if you want to use JSTL tags, you must import the declare the taglibs, just like you do now in Tomcat 4.x.

2. The EL is turned off by default if you have a 2.3 DTD for your web.xml. If you have a 2.4 XSD in web.xml, the EL is turned on by default. This means that you can write ${param.foo} and it will be analyzed when the EL is on (when off, it's not analyzed).

3. You can replace <html:rewrite page=""/> with <c:url value=""/> and get the same effect. The only difference is that html:rewrite is context and module-sensitive, whereas c:url is only context-sensitive.

4. I had to replace the URI's for JSTL core and fmt with their run-time URIs - http://java.sun.com/jstl/core_rt vs. http://java.sun.com/jstl/core. Otherwise, I would get something similar to the the following error.

According to TLD or attribute directive in tag file, 
  attribute test does not accept any expressions

I figure upgrading to JSTL 1.1 might solve this issue, but since it hasn't been released, why bother? So to convert appfuse to be a JSP 2.0 webapp, here's what my Ant task does:

  • Replaces URIs with their run-time equivalent.
  • Removes <c:out> tags, leaving the value of the "value" attribute intact.
  • Replaces 2.3 DTD in web.xml with 2.4 XSD.

I did some (rough) benchmarking of running my JSP tests, here are the results on a Pentium IV (2 GHz, 512 MB RAM).

start Tomcat, run tests, stop Tomcat:
 Tomcat 4.1.24: 1 minute, 17 seconds
 Tomcat 5.0.4: 1 minute, 7 seconds
 Tomcat 5.0.4/JSP 2.0: 1 minute, 3 seconds

run tests, Tomcat already started:
 Tomcat 4.1.24: 33 seconds
 Tomcat 5.0.4: 22 seconds
 Tomcat 5.0.4/JSP 2.0: 22 seconds

According to these numbers, Tomcat 5 is quite a bit faster than 4.1.x.

Posted in Java at Jul 17 2003, 01:27:01 PM MDT 5 Comments

Upgrading to latest WebTest and Cactus

I attempted (and succeeded) in upgrading to the latest and greatest releases of Canoo's WebTest and Jakarta's Cactus this afternoon. It wasn't too bad. Both have revised their taskdef's to read from a properties file, and Cactus has simplified the process to include cactus-related JARs/mappings in your webapps. Now you can "cactify" your war with a little Ant-lovin:

<cactifywar srcfile="${webapp.dist}/${webapp.war}"
    destfile="${webapp.dist}/${webapp.name}-cactus.war">
    <lib dir="${strutstestcase.dir}" includes="*.jar"/>
    <lib dir="${cactus.dir}">
        <include name="*.jar"/>
    </lib>
</cactifywar>

Pretty slick IMO. Now if I could only figure out how to do form-based authentication with Cactus (I couldn't find it in the docs).

The other issue I've been banging my head against the wall over is running canoo/httpunit tests with a compression filter enabled. Yep, the problems still exist, despite the fact that I patched httpunit. So I've come up with a new fix that satisfies me and eases the pain in my noggin'. In my compression filter, I simply disabled compression when it's an httpunit test:

String userAgent = req.getHeader("User-Agent");
if (!isGzipSupported(req) || userAgent.startsWith("httpunit")) {
    // Invoke resource normally.
    chain.doFilter(req, res);
} else { 
    // gzip it
}

Posted in Java at Jul 15 2003, 07:05:36 PM MDT 2 Comments

Fun with Tomcat 5.0.4

After reading Dave's post about Tomcat 5, I got interested and decided to try it out. For those that don't know, Tomcat 4.0.5 Alpha was released today. I figured out how to make AppFuse run through a series of steps. Basically, I had to put log4j.jar in $CATALINA_HOME/common/lib and appfuse.xml in $CATALINA_HOME/conf/Catalina/localhost. Details are on my wiki.

Posted in Java at Jul 15 2003, 04:14:15 PM MDT Add a Comment

Struts: How to use Indexed Properties

James Turner has written a short-n-sweet article on using indexed properties with DynaForms. Of course, you could use any ol' ActionForm, but you get the idea. If you're struggling with indexed properties in Struts, or you're just curious to know what they are, read this article (estimated time 5-10 minutes, 6 printed pages - mostly code).

Now if we could only convince James to use XHTML (lower case HTML, close your tags, etc.) in his examples. wink A big pet-peeve of mine is uppercase HTML - XHTML is lowercase and HTML works just the same with lowercase tag names/attributes. Here's to future compatibility!

Posted in Java at Jul 14 2003, 11:07:10 AM MDT 2 Comments

Prevent Caching of JavaScript and CSS files

We've been having an issue at work for awhile now where our .css and .js files are cached by a proxy server. When we update the app, we get a few users (behind the proxy server) that get served up an old style/script file, and the app looks like it's broken. So I added a super-simple cache-killer to our .js and .css files today. In my taglibs.jsp (included in every JSP), I added:

<%-- Create a variable that is the current time (in milliseconds) to kill
     caching on the proxy server --%>
<jsp:useBean id="now" class="java.util.Date" />
<c:set var="cacheKiller">
    <fmt:formatDate value="${now}" pattern="yyyyMMdd"/>
</c:set>

My date pattern only goes to the day because we don't update the site more than once in the same day. This way, the users will still get the stylesheet/script caching benefit of the browser, but now we control when the file is reloaded, rather than the proxy server. To make sure these files are re-fetched every request, you could use pattern="yyyyMMddHHmmssS" to get all the way down to the millisecond. After adding this, I adjusted my baseLayout.jsp (Tiles template) to add my cacheKiller as a parameter to the src attributes of scripts and stylesheets.

<%-- Get Javascript List --%>
<tiles:useAttribute name="scripts" ignore="true"/>

<c:forEach var="js" items="${scripts}">
    <script type="text/javascript"
        src="<html-el:rewrite page="${js}"/>?<c:out
             value="${cacheKiller}"/>"></script>
</c:forEach>

Works like a charm!

Posted in Java at Jul 14 2003, 10:16:48 AM MDT 6 Comments

Words of Wisdom from James Gosling

After reading James's All I Really Need to Know I Learned while Skiing with my Grandmother (damn, no permalink), I've come up with a Raible Developer Creed.

  • Balance - strive for it. If you're staying up late to develop, and you haven't spent a few hours with your friends/family that day - you're not being fair to yourself, or them.
  • You're breathing too hard. You must be doing something wrong. Take the time to learn before doing. This is going to be a tough one as I tend to just jump in and try to do something. However, I'm sure if I studied the technology/documentation first, it would actually take me less time to do it.
  • Inspiration is 99% Observation. I'm going to try to limit how much I do outside of the office and start observing more (via mailing lists/blogs). This will contribute greatly to the first item in my new creed.

Posted in Java at Jul 11 2003, 12:11:02 PM MDT Add a Comment

Feeling the love

Thanks to Erik for choosing me as one of his favorite Java bloggers. That's quite a compliment in my book - especially from one of my favorite bloggers.

Since it's Friday, here's a mp3little reminder.

Posted in Java at Jul 11 2003, 07:01:55 AM MDT Add a Comment

JSP 2.0 Article in July JDJ

I got the July issue of JDJ today. In it I found a good article on JSP 2.0 (printable, less ads version). Things I learned from the article:

  • JSTL 1.1 will introduce 16 standardized EL functions:
    - fn:length(): Get the length of a collection or a string.
    - fn:toUpperCase(), fn:toLowerCase(): Change the capitalization of a string.
    - fn:substring(), fn:substringBefore(), fn:substringAfter(): Get a subset of a string.
    - fn:trim(): Trim whitespace from a string.
    - fn:replace(): Replace characters in a string.
    - fn:indexOf(), fn:startsWith(), fn:endsWith(), fn:contains(), fn:containsIgnoreCase(): Check if a string contains another string.
    - fn:split(): Split a string into an array.
    - fn:join(): Join a collection into a string.
    - fn:escapeXml(): Escape XML characters in a string.
  • The tag libraries in JSTL 1.1 have new URIs (for example, http://java.sun.com/jsp/jstl/core instead of the JSTL 1.0 equivalent http://java.sun.com/jstl/core_rt). The new JSTL 1.1 tag libraries accept request-time expressions for their attributes, and delegate to the JSP container to evaluate EL expressions.

Good stuff to know. I'm ready to start developing JSP 2.0 apps - I hope the Tomcat dev team releases a stable build soon. Or maybe I should just look into using Resin...

Posted in Java at Jul 10 2003, 09:54:44 PM MDT 4 Comments

Compression Filter Issues - EOFException

I'm having some issues with implementing a Compression Filter in my day-time project. It works fine via the browser (and in AppFuse/Roller), but not in one of my Webtests. I think this is because my response doesn't have anything in it, but who knows. From my log file:

CompressionFilter.doFilter(87) | Unzipped size: 0
CompressionFilter.doFilter(106) | Zipped size: 20

And then the lovely error message from my testcase:

[canoo] java.io.EOFException
[canoo]     at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:200)
[canoo]     at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:190)
[canoo]     at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:130)
[canoo]     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
[canoo]     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
[canoo]     at com.meterware.httpunit.WebResponse.defineRawInputStream(WebResponse.java:617)

I'm thinking I need to close a stream or something, but since it works fine via the browser - I'm stumped! Any ideas are appreciated. I can post the testcase if necessary.

Update: Richard Hill on the Webtest mailing list hooked me up with the solution. It turned out to be a bug in the JDK, which causes issues in HttpUnit. Here's the solution I used to workaround it.

Posted in Java at Jul 10 2003, 04:59:51 PM MDT 2 Comments

Changing Struts' bean:message to JSTL's fmt:message

I converted AppFuse to use JSTL's <fmt:message> tag instead of Struts' <bean:message> tags this morning. It was pretty easy. Here's the steps I took:

1. First, I added the following to metadata/web/seb-settings.xml:

<!-- Define the basename for a resource bundle for I18N -->
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>ApplicationResources</param-value>
</context-param>

2. Then I added the format tag to web/common/taglibs.jsp:

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

3. Finally, I did find/replace with <bean:message/<fmt:message.

4. I also had to change my title and header keys in web/WEB-INF/tiles-config.xml to remove the . from the bean names. In other words, I converted title.key and heading.key to titleKey and headingKey and also made the appropriate changes in web/layouts/baseLayout.jsp.

Easy as Pie!

Posted in Java at Jul 10 2003, 07:59:29 AM MDT 35 Comments