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 "jsps". 109 entries found.

You can also try this same search on Google.

[AppFuse] Use Velocity instead of JSPs for your view?

If you want to use Velocity Templates instead of JSPs in your AppFuse-based web application, Cameron Gray has figured it out. Not only did he figure it out, but he was nice enough to write up a tutorial on it. Thanks Cameron - the time you took to write the tutorial is greatly appreciated.

In other AppFuse news, Rick Hightower seems to have convinced it to work with MyEclipse, JBoss and the Firebird database. Also, I received a few messages this week and I think another user has convinced it to run on Orion/Oracle successfully! If I ever get motivated, I'll try to put How-Tos on the wiki for all of these.

Posted in Java at Jan 31 2004, 10:01:59 AM MST

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

RE: AppFuse (Getting started with...)

Rick Hightower has started using AppFuse. It looks like he had a couple of issues, so I figured I'd post some solutions here for all to see (also because typing in comments w/o HTML on JRoller sucks).

Rick - I don't know why you're getting the first error with CATALINA_HOME. I just tried removing that as an environment variable on my PowerBook and I'm able to run "ant setup-db" just fine. If you've setup the MySQL database with the default settings, you should end up with a "root" user and a blank password. These settings are both specified in properties.xml, where database.admin.username=root and database.admin.username=(nothing). Of course, you can change these properties values by editing properties.xml, or by specifying them in your build.properties file. From the following error on your site:

db-load:

BUILD FAILED
C:\source\appfuse\build.xml:931: java.sql.SQLException: Invalid authorization sp
ecification,  message from server: "Access denied for user: 'rick@localhost' (Us
ing password: YES)"

It looks like you have an administrator named "rick", but that your password was incorrect. YES is not the password you provided - that's just MySQL saying that you did provide a password.

The database creation script is at metadata/sql/mysql-create.sql and it simply creates an "appfuse" database and gives a user named "test" access to it.

create database if not exists appfuse;
grant all privileges on appfuse.* to test@"%" identified by "test";
grant all privileges on appfuse.* to test@localhost identified by "test";

The next error about j2ee.jar should be self explanatory and it looks like you figured that one out. I wish I didn't have to include the entire j2ee.jar in the classpath, but XDoclet requires javax.ejb.* JARs be in the classpath for generating Struts ActionForms from POJOs.

The last thing you did - ant -Dapp.name=sampleApp -Ddb.name=database - was to merely run the "package-web" target. It's the default target in build.xml. It simply compiles everything and packages into an appfuse-1.3.war file. In this scenario, the app.name and db.name mean nothing. If you want to create a new AppFuse project, you need to specify the new target. This will create a new project.

foxxy:~/dev/appfuse mraible$ ant new -Dapp.name=test -Ddb.name=test
Buildfile: build.xml

clean:
     [echo] Cleaning build and distribution directories
   [delete] Deleting directory /Users/mraible/workspace/appfuse/build
   [delete] Deleting directory /Users/mraible/workspace/appfuse/dist
   [delete] Deleting: /Users/mraible/workspace/appfuse/database.properties

new:
     [echo] Creating new application named 'test'...
     [copy] Copying 318 files to /Users/mraible/workspace/test
     [copy] Copying 1 file to /Users/mraible/workspace/test

BUILD SUCCESSFUL
Total time: 21 seconds

I just tried this, followed by the commands specified below and all seems to be working just fine (BUILD SUCCESSFUL - Total time: 5 minutes 13 seconds).

cd ../test
ant setup-db
ant setup-tomcat
ant test-all

Just to be clear, here's a breakdown of what the above targets do:

  • setup-db: creates a database for the project, assigns users, creates all the tables and populates it with test data.
  • setup-tomcat: copies a context.xml file to $CATALINA_HOME/webapps and copies the database driver to CATALINA_HOME/common/lib.
  • test-all: runs all the tests to verify the functionality of the app. These include test-ejb for the DAO layer, test-canoo for all the JSPs and test-web for all the StrutsTestCase/Cactus tests and business layer tests (*ManagerTest).

The first steps after creating a new AppFuse project are probably to rename the packages to fit your company's naming convention - i.e. org.appfuse -> com.company.appname. In Eclipse (and propably IDEA), this is fairly easy. Just make sure to do it in the "src" and "test" directories, as well as search for it - it might be specified in a few XML files (i.e. hibernate.cfg.xml). You'll also need to modify the "javadoc" target to ensure that it looks for the write package names. Currently, it's set to "org.*".

Hope this helps!

Posted in Java at Jan 19 2004, 05:55:25 AM MST 1 Comment

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

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

Useless Tag Library?

Inspired by this post, I wrote a tag library to expose the fields of my Contants.java class to my JSPs. It allows a user to specify a single variable using:

<appfuse:constants var="USER_KEY"/>

Or all variables:

<appfuse:constants/>

By default, it exposes the values from the Contants class imported into the tag library, but also allows a className variable to specify a different class. The main reason I wrote this was to prove it was possible. The second reason was to get around importing my Contants class (and using <%=Contants.VARNAME%>).

Interested? Read More ...

Posted in Java at Dec 31 2003, 08:25:57 AM MST 1 Comment

Export JSPWiki pages to HTML using Hula

This morning, I discovered Hula - a Java client API to the WikiRPCInterface. The nice feature I really like is that it allows you to export your wiki pages to static html. Here's how to set it up on your JSPWiki:

  • Uncomment the XML RPC servlet-mappings in web.xml.
  • Download Hula.
  • Rename hula.zip to hula.jar and put it into JSPWiki's WEB-INF/lib.
  • Copy apps/*.jsp to webapps/JSPWiki/.
You can use my trimmed down version if you like, it only has hula.jar and the JSPs.

Now I can write all my AppFuse documentation on the wiki and bundle it with the downloads - very nice.

Posted in Java at Dec 11 2003, 11:52:03 AM MST 3 Comments

StrutsCX - Updated Demo

I've updated my demo of StrutsCX. I haven't looked at StrutsCX much, but this release does look pretty polished. A quick glance tells me that it's now ready to be simply included in your Struts app with a single .jar file. Very nice! I might have to use it in Struts Resume to generate PDFs of Resumes.

Posted in Java at Dec 04 2003, 04:23:02 PM MST 2 Comments

AppFuse 1.0 Released!

I feel this release deserves the big 1.0 designation because it is an up-to-date representation of my learnings and my perceived best practices in building web applications. Of course, as I learn more, I will continue to push out new releases.

In this release, I did a lot of refactoring and enhancements to existing features. The DAO and Manager interfaces are no longer tied to Struts or Hibernate. Hibernate's Session object is now passed as an argument into Manager and DAO constructors, rather than method signatures. The DAOFactory was refactored by Bear Giles to use reflection to instantiate Hibernate DAO's. Now, if you add a new DAO, you don't have to edit DAOFactory and DAOFactoryHibernate. To insantiate a new DAO, the code is now:

LookupDAO dao = (LookupDAO) DAOFactory.getInstance(conn, LookupDAO.class);

...where conn is a connection object retrieved from ServiceLocator or ActionFilter. When you add new POJOs, you still have to add them to ServiceLocator (for JUnit tests) and hibernate.cfg.xml, which is kindof a pain. I'd like to figure out a way to tell Hibernate to just look in appfuse-ejb.jar.

<tangent>
I still don't have a Factory for Managers, and I don't know that there's a need for one, but it's something I might add in the future. Managers are still creating using: LookupManager mgr = new LookupManagerImpl(ActionFilter.getConnection());. One thing I've been thinking about is the ability to switch webapp frameworks - kindof like you can do with Persistence Frameworks and the DAO Pattern. It'd be cool to add a way to switch (at build time) to use WebWork or Tapestry. Maybe by replacing values for the controller in web.xml. It'd probably be a pain since I'd probably have to create new JSPs for the new frameworks - but it would probably be a great learning experience.
</tangent>

The Remember Me feature has been refactored so the username and password cookies are only available under the /appfuse/security url-pattern. I also changed the posting to "j_security_check" in LoginServlet from response.sendRedirect to an HTTP POST, using Jakarta Common's HttpClient. The reason I have a LoginServlet vs. just using action="j_security_check" in my <form> is to encrypt passwords.

I've developed 3 different applications using AppFuse (struts-resume is one of them), and I have found that it's a pain to upgrade to new versions of AppFuse. Because of this, I don't recommend upgrading unless you really need to. I will be upgrading struts-resume to AppFuse 1.0, but I doubt I'll upgrade it to any future AppFuse releases - it's just too much work for not much reward.

Posted in Java at Nov 30 2003, 06:35:24 PM MST Add a Comment

My Favorite Eclipse Plugins (Download v1.0)

When I go to new clients, I either have to install Eclipse, or help others configure Eclipse with cool plugins. So I made my own download of my favorite Eclipse plugins. If you want it, download version 1.0 from SourceForge. It includes the following:

Installation: Unzip to where ever you have Eclipse installed. I use c:\Tools\eclipse on Windows.

I don't really use XMLBuddy because it doesn't allow spaces (only tabs), but I suppose it's better than nothing. The built-in Ant Editor has the same behavior (tabs only). I'd love to find a plugin that gives code-completion for XDoclet when typing JavaDocs, but I couldn't find one. Sure, there's JBoss-IDE (which is just a bunch of Eclipse plugins), but that only has jboss-specific tags - no @hibernate, no @struts.

NOTE: Many of these plugins didn't work on Eclipse 3.0 M5, so I reverted back to M4.

OS X Users: Jalopy and Colorer don't seem to work at all for me (M4). You'll need to change Easy Explorer from "explorer.exe {0}" to "open {0}" in Window > Preferences > Easy Explorer.

These are all the latest versions as of November 26, 2003.

Posted in Java at Nov 26 2003, 01:02:59 PM MST 13 Comments