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.

JSTL and Dreamweaver has JSP Tag Completion

I discovered today that there is are new releases of the JSP Standard Tag Library over at Jakarta's Taglibs project. JSTL 1.0 has a Standard 1.0.4 release from September 25th, and there's also an early access 1.1 release (for Servlet 2.4/JSP 2.0). If you're doing JSP development and you're not using JSTL, you'd better start - these tags are huge timesavers and are fairly easy to learn (especially if you know JavaScript).

I also discovered a nice feature in Dreamweaver 2004 - Tag Library code completion. I believe Dreamweaver MX (v6.0) had this as well, but I never use DW on a PC (it's too slow). Now that I'm giving a go at using OS X all the time, I need to use DW so I can get an explorer-like window (BBEdit doesn't seem to have this). It's pretty slick - you just import the .tld or .jar and whalla - you've got tag library code completion. The one downside is that it does not support importing multiple libraries from one JAR file (i.e. Struts or JSTL), so you do have to import the .tld files (selecting all .tld files in a directory works). It might actually be worth the $400 if I keep developing on a Mac. I don't know about IDEA - I started using Eclipse today after using IDEA for the past week and it felt like I was home again.

Lastly, iBatis has a new release. I upgraded from 1.2.7b to 1.2.8 in my current project and all our tests ran without a hitch. Gotta love unit tests.

Posted in Java at Oct 16 2003, 05:19:39 PM MDT 4 Comments

OS X Rocks, but it sucks too

OS X is awesome ~ it's beautiful to look at and it's based on Unix. What more could you ask for? Windows XP looks good, RedHat 9 doesn't. Windows XP with Cygwin is almost tollerable, but you still have to type "cd c:" when you want to change drives. What bugs me about OS X is simple *nix things don't work on it. Integrating Apache + Tomcat is a 5 minute job on WinXP and RH 9, but I've spent the at least 10 hours trying to do it on OS X with no luck. I could post the errors here, but what good would it do? This kind of stuff just works on RH 9 and WinXP. Therefore, OS X sucks!

What am I ranting for? No reason really - it just sucks that I've spent so much time trying to do something that still doesn't work. This HowTo didn't help either (building from source had errors, no binary of Apache available). I guess this is all due to the fact that OS X has a 1% (maybe 2%) market share among developers?

Posted in Mac OS X at Oct 12 2003, 06:54:12 PM MDT 13 Comments

PHP vs. Java - which is better?

I have a former client that has a customer. This customer asked them - "so when are you migrating from Java to PHP?" So evidently this person has the impression that the next wave of web applications will be written in PHP. My former client has asked me to provide an answer for their customer. If I translate it, I think they mean to ask "what is different between Java and PHP and why should we use Java over PHP." Here are my opinions - please add yours as you see fit. I must admit I don't know a whole lot about PHP, except that it's widely popular among the Linux/Apache/MySQL crowd and that it's similar to ASP in it's lack of a MVC architecture (yes, I know about the PHP MVC project).

  • I think Java is more of an industry standard, whereas PHP seems to be popular among hackers and hobbyists.
  • Java provides better separation of layers - key for testability. PHP has all the code embedded in the page, so you have to run it through a browser to test if database connections work (for instance).
  • Java is more scalable.
  • More folks know Java and it's easier to qualify someone's Java skills. How do you test someone knows PHP? Is there a certification?
  • More for-profit organizations use it.

If you're a Java or a PHP-lover, I'd love to hear your opionions (facts are always better). I'm going to point my client to this post, so keep it clean.

Posted in Java at Aug 22 2003, 03:52:33 PM MDT 98 Comments

Building high-content web applications

I've recently been tasked with rebuilding a JSP-based site using a Struts architecture. One of the issues (that I see) in the current architecture is that there are a number of JSPs with the text for the pages hard-coded in them. After re-writing this app, we plan on deploying it to 25+ customers - and we certainly don't want to have 25 different JSPs (with text) for each customer. I've proposed a database, but that might be a little resource intensive - so I'm wondering how folks have done this in the past (I'm sure it's been done before)?

Options I see are:

  • A Database table with the following columns (page_id, title, content, section_id).
  • Text files that are imported using <c:import url=""/>

What options have you used (feel free to add more) - if you've used the database approach - how do you define the page table? Maybe we should use the Roller way and use Velocity and OSCache.

Posted in Java at Aug 19 2003, 06:30:28 PM MDT 18 Comments

Help me architect Struts Resume

I've come up with a few issues for Struts Resume that I need some feedback on. Let's just get right to them. * How should I assign skill groups and skills to a resume? * Resume Templates - should I do something like Roller or simpler? * Can I produce PDF or RTF from a Velocity template? I've [elaborated more|StrutsResumeArchitecture] on my wiki. Please post your feedback via comments or on the wiki.

Update: Thanks to Mathius, I was able to implement a simple XHTML and RTF (Word) version of a simple resume today. I don't think Velocity will be the only option, I think I'm going to have to have an XSL Transformation Servlet as well, and the user will be able to choose Velocity templates or XML/XSL/FO. But that will be in a later version of Struts Resume. For 1.0, I'm going to concentrate on getting a resume updateable and presentable - PDF will be a post-1.0 option. The main reason for this is because I think I can release a 1.0 version before my next gig starts. After I start, it might be quite a while until I can get some time to work on it again.

Posted in Java at Aug 05 2003, 08:02:59 AM MDT 5 Comments

Monday Morning Mayhem

My Inbox was attacked over the weekend with all kinds of good links and fun stuff to post. So here it is:

  • LogWeb was released. A fully functional web interface for the runtime configuration of log4j within servlet containers and j2ee application servers. I won't use it, as I've never been inclined to change my logging configuration at run-time. And if I do need to change it, reloading my app isn't a big deal with Tomcat. Although, it might be nice to view your apps' configuration with this tool.
  • Mozilla and XUL for Cross-Platform User Interfaces, a Tutorial. Quick, easy and works with Mozilla Firebird. I did the examples.
  • StrutsDoc 0.3 was released. StrutsDoc is an Ant task that generates JavaDoc-like documentation from a Struts configuration file. StrutsDoc currently only supports the 1.1 version of Struts. [StrutsDoc Example] This might be helpful for documentation (a.k.a. impressing management) and bringing new developers up to speed.
  • Rowell has approved the use of his theme in Roller. I'll make sure and add a "designed by Rowell Sotto" to the bottom of the theme. Theme names are welcome. Currently, it's named "sotto."
  • Tomcat 5.0.5 Alpha was released. I'll comment here later today.

The best part of the day (so far)? My bike ride to work went from 1 1/2 hours (one-way) to 45 minutes - I just gained an hour and a half in every weekday!

Posted in Java at Jul 28 2003, 08:46:33 AM MDT 1 Comment

Roller Searching - Powered by Lucene

Lucene Logo

Thanks to Min, we now have searching in Roller. He wrote a wicked-ass Lucene implementation using the util.concurrent package from Doug Lea. Here's how it works:

  • When Roller starts, it checks to see if the index is OK, and if not, rebuilds it. The index then goes into RAM and stays there until you destroy the servlet context - then it's written to disk. The location is configurable, but defaults to $(user.home} + File.separator + "roller-index".
  • A user's index is updated when they add/delete weblog entries.
  • A user can rebuild their own index via a button on the Website Settings page.
  • An Admin can rebuild a user's index from the "Admin" page and rebuild all users' indexes from the Config page.
  • The IndexManager is the central entry point, and it lives in RollerContext.getIndexManager(). For indexing, searching, etc. you use one of the following operations:

    - AddWeblogOperation
    - RebuildUserIndexOperation
    - RemoveWeblogOperation
    - SearchOperation

    After creating these ops, set any op-specific configuration options and then pass it to the IndexManager.executeIndexOperation() method.
  • Behind the scenes, there is an background thread running. This thread only performs one operation at a time. If an op is added when the thread it busy, the op will be queued. The way Lucene works is that most operations can be threaded. Lucene supports the concept of add, delete, read, query, and optimize. The only methods that cannot be active at the same time are IndexReader::delete() and IndexWriter::add(). Therefore, the operations that perform these operations are put into the background thread queue that garantees that these ops wont be performed at the same time. Searching doesn't interfere with these ops, so it can be run in any thread.

I created a #showSearchForm macro that renders a <form> with a textbox (size=20) and a "Search" submit button. I also added this to all the current themes - so if you developed a theme for Roller - you might want to check it out (username: test, passwd: roller). You can edit it right on the site if you want, then copy/send me the adjusted files. CSS seems to need the most tweaking for these to look right.

Please enter any bugs/enhancements in Roller's JIRA instance. The only one I've seen so far is that a user has to build their index manually before they get any search results. I don't know that this is a bug, just wanted to mention it. Doesn't get comments yet either - a NPE from weblogMgr.getComments() (when adding a new post) kept me banging my head against the wall for an hour - so I commented it out.

Try it, you might like it. ;-)

2 minutes later: Here's a bug - if you update an entry numerous times, it will get presented as numerous times (should be deleted and re-indexed).

Posted in Java at Jul 22 2003, 11:41:59 PM MDT 2 Comments

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

[Denver JUG] The J2EE 1.4 Web Foundation: Servlets and JSPs

I'm sitting in the Qwest Auditorium right now, in the heart of downtown Denver. It's 7:20 p.m. and Sue Spielman is getting ready to launch her presentation on J2EE 1.4. There is a gentleman who is trying to start a JBoss Special Interest Group - if you live in Denver and are interested - send an e-mail to the DJUG mailing list. I've been here since 5:45 (after driving an hour from DTC) so this better be good. ;-) The Eclipse in Action speaker (David Gallardo) is coming to speak in October. In September, the author of AspectJ is coming in conjunction with Grady Booch. Never heard of him, but judging from the applause - I'm living under a rock.

On with the presentation. Sue thinks that J2EE 1.4 will be released towards the end of this year. Damn, I was hoping for the end of the summer.

What's new in Servlets 2.4?

1. Platform Requirements:

  • HTTP/1.1 - New static constants. HttpServletResponse.SC_FOUND to represent status code 302 instead of HttpSerlvetResponse.SC_MOVED_TEMPORARILY.
  • J2SE 1.3

2. DTD to XML Schemas:

  • Provides easier way to define element structure, element ordering structure is arbitrary under <web-app>
  • New elements in 2.4 XSD: <env-entry>, <resource-ref>, <resource-env-ref>, <jsp-config>

3. Complete event listener lifecycle:

  • New Request Events. Be aware that distributed containers handle listeners a bit different (1 instance per JVM).
    • ServletContext - manage, startup/shutdown, attribute changes
    • HttpSession - creation, invalidation, attribute changes, migration if sessions distributed
    • Request - request coming in or out of scope in a web component, attribute changes
  • javax.servlet.ServletRequestEvent, ServletRequestAttributeEvent
  • new interfaces ServletRequestListener, ServletRequestAttributeListener
  • SessionActivationListener is what you'd use for serializing sessions across a cluster

4. Filter enhancements:

  • Ability to configure filters to be invoked under request dispatcher. What does "under the Request Dispatcher mean?" It means that you can apply filters under RequestDispatcher forward() and include() calls. Defined in web.xml:
  • <dispatcher>REQUEST</dispatcher> and/or FORWARD, INCLUDE, ERROR (REQUEST was the only option in Servlets 2.3)
  • Example: if you have INCLUDE - a request doesn't invoke the filter, a forward doesn't invoke the filter, but an include would.

5. Enhancements for i18n:

  • Two new methods: setCharacterEncoding(String encoding) - do before getWriter() and getContentType().
  • <locale-encoding-mapping-list> - new element in the XSD to provide the deployer with the ability to assign locale-to-charset mappings outside servlet code.
<locale-encoding-mapping>
  <locale>en</locale>
  <encoding>en_US</encoding>
</locale-encoding-mapping>
  • Response encoding for English locales will default to US English (as opposed to the "other" English from Great Britain) ;-)

6. API Improvements added to the ServletRequest to help handle proxy servers: getLocalAddr(), getLocalName(), getLocalPort(), getRemotePort().

7. Other improvements:

  • Distributed sessions must throw an IllegalArgumentException if an object placed in the session can't be serialized
  • Relationship b/w session invalidate/timeout clarified (can now set zero or negative values in <session-timeout>)
  • Deprecation of Single ThreadModel (never used it - did you?)

8. Misc. Clarifications:

  • Welcome files can be servlets
  • Any library files exposed by the container apart from the WEB-INF structure must be loaded by the same classloader w/in any single JVM.
    • Examples include the JARs Tomcat loads from $CATALINA_HOME/shared/lib
    • This should help in avoiding potential ClassCastExceptions

As I expected, there still is now way to get the user's requested URL with container managed authentication. Damn.


JSP 2.0

1. Simplifies tag extension protocol

  • SimpleTag interface: doTag(), Tag attribute methods, NO scriplet code allowed
  • SimpleTagSupport class, implements SimpleTag, adds convenience methods: public JspFragment getJspBody(), public JspTag getParentTag()

2. Relationships: .tag file mechanism allows page authors to use JSP syntax to write custom actions

  • Use directive standard syntax: <%@ tag %> instead of <%@ page %>
  • JSP compiler generates custom action code (look in Tomcat's work directory)
  • Flexible packaging:
    • drop .tag file into WEB-INF/tags
    • implicit tag library generation
    • can still write a TLD if you want, or TLD in a JAR file

3. EL Functions: simple function invocations, defined in tag libraries, but it's a fair amount of work - like writing a TLD file and .java source file.

4. Expression Language:

  • . and [] operations access JavaBean properties and Collection elements
  • ${books.title}, ${books[title]}, ${books["JSTL Practical Guide"]}
  • Automatic type conversion
  • Ability to specify defaults (i.e. in case of null)
  • EL can access Cookies, request params, headers, scope variables and others

5. XML-based JSPs:

  • .jspx and .tagx for pure XML versions
  • no more <jsp:root> just use namespace: xmlns:jsp=http://www.sun.com/JSP/Page
  • For full list of XML features - see section 6.

JSTL (Java Standard Tag Library)

  • Over 42 standard custom actions available for common tasks needed by page authors
  • JSTL will become rev 1.1 in the J2EE 1.4 release

1. Core features:

  • Control flow: for each, conditionals
  • URL management: encoding, ftp, http
  • Formatting and i18n: date, time, numbers, locales
  • XML: transformations and XPath
  • Database support: queries, data sources, transactions
  • 4 custom action libraries: core, xml, i18n formatting, sql.

Man, Sue really knows her stuff. This was a very enjoyable presentation for me and I'm glad I came. Too bad JSPs can't be used as templates like Velocity - that would be sweet! Of course, I like Velocity and it is easy to use - but I've never implemented it from scratch. I do hope to in Moblogger and Struts Menu, but who knows when that will happen.

Update (7/17/2003): Presentation slides from this are now available for download:

  • July 9 - Basic Concepts: Scott Davis Apache Xerces - XML Parse (PowerPoint and samples)
  • July 9 - Main Speaker: Sue Spielman J2EE 1.4 Web Foundation (PowerPoint)

Posted in Java at Jul 09 2003, 11:15:44 PM MDT Add a Comment

Tomcat/Oracle Connectivity Problems

I had a problem that I thought I fixed a while back. The problem was that our firewall between Tomcat and Oracle would close our database connection after 90 minutes of inactivity. We first solved this problem by using a Servlet/Ant Task/cron job combination to ping and use the DBCP connection pool we'd configured in Tomcat. This worked, for a little while. Then we realized we had to also ping the JDBCRealm, so we used a login test (via WebTest) and added this to our Ant Task/cron job. Again, this worked for a couple of months, until a QA Expert came on board and starting using WAPT to load test our app. Then we began having issues with many connections being opened (20+), then they were closed by the firewall, and when the app would try to re-use these connections, they wouldn't respond, and the app would enter into the "dithering idiot" mode. We finally figured out a solution, rather than workarounds, and here it is:

// In the file:
$ORACLE_HOME/network/Admin/SQLNET.ORA

// Add the following line to check every 10 minutes
SQLNET.EXPIRE_TIME=10

Posted in Java at Jun 02 2003, 09:25:58 AM MDT Add a Comment