Sunday, November 7, 2010

Darn it JSPs!

I learned something really neat... well not so neat about JSPs and how they get compiled.  Say you have something like this:

<% if (request.isUserInRole("user")) { %>

<p>Hey, let's do something with this user role business</p>


<% } %>
<% else if( request.isUserInRole( "guest" ) ) { %>

<p>Let's do something with the guest role </p>

<% } %>

You would think it would work. There's an if statement, then an else if statement... Except, when the JSP compiles, it looks like so:


if (request.isUserInRole("user")) {
      out.write("\n");
      out.write("\n");
      out.write("
<p>Hey, let's do something with this user role business</p>\n");
      out.write("\n");
      out.write("\n");
 }
      out.write("\n");
      out.write("\n"); 
else if( request.isUserInRole( "guest" ) ) {
      out.write("\n");
      out.write("\n");
      out.write("<p>Let's do something with the guest role</p>\n");
}
 Because of those newlines, the if/else if doesn't look right and it throws errors when you run. The only way I was able to get it to work was to put the close brace and the else if in the same statement:

<% } else if( request.isUserInRole( "guest" ) ) { %>

Once that was done, the thing compiled properly and worked fine. A neat little thing to keep in mind when throwing scriptlets in the JSP.

Monday, October 25, 2010

Why can't I view JSPs on my Linux box?

This is a bit insane I must say. I have the following setup: Eclipse Helios, 64-bit JDK (1.6.0_21), Tomcat 6 (6.0.29), and a pretty straightforward JSP that does nothing other than evaluate the date.

I get this crap all the time:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:268)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
test.test01.MainServlet.goToPage(MainServlet.java:50)
test.test01.MainServlet.doGet(MainServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause


java.lang.NoClassDefFoundError: javax/el/ELResolver
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
java.lang.ClassLoader.defineClass(ClassLoader.java:616)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
java.net.URLClassLoader.access$000(URLClassLoader.java:58)
java.net.URLClassLoader$1.run(URLClassLoader.java:197)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
java.lang.ClassLoader.loadClass(ClassLoader.java:307)
java.lang.ClassLoader.loadClass(ClassLoader.java:296)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
java.lang.ClassLoader.loadClass(ClassLoader.java:296)
java.lang.ClassLoader.loadClass(ClassLoader.java:248)
org.apache.jasper.runtime.JspFactoryImpl.getJspApplicationContext(JspFactoryImpl.java:209)
org.apache.jsp.WEB_002dINF.jsp.search_jsp._jspInit(search_jsp.java:22)
org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
test.test01.MainServlet.goToPage(MainServlet.java:50)
test.test01.MainServlet.doGet(MainServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 I have checked everything I can think of (JAVA_HOME, CATALINA_HOME variables) and all check out okay. The project in eclipse is a dynamic web project and has all the $CATALINA_HOME/lib jar files in it including the el-api.jar file.

So what gives? The real annoying thing about this whole process is that I can export the war file, pop it onto my windows machine and it works just fine! I tried doing the same with Tomcat on Ubuntu and running it from there directly but am no better off. So, anyone know what the heck I am doing wrong?

Thursday, June 3, 2010

Dynamic graphing in the web world

Instead of studying for my midterm, I am sitting here wondering if there is a way to create and interact with dynamic graphs in the web-based world. I don't know of too many things that are even out there that behave in the manner I envision, apart from perhaps the charts in google finance.

What I want to accomplish can be done using Swing and Java. I suppose I could create an applet that allows you to interact with the data and do things with it. My main motivation for having the ability to interact with data is the following use-case. 

Where I work, we use an HP tool called LoadRunner. It has a fairly useful (if sometimes annoying) tool called LoadRunner Analysis. This tool allows you to dynamically select regions of the various graphs it displays to the end user and then does stuff (in this case, updates the data you see to align with the regions of the graph you selected). Data it presents includes things like averages of whatever you happen to be looking for on the graph, max, mins, that sort of thing. 

We also have similar data externally. One example is the verbose GC logs of the JVM we use. It would be useful if I could find a way to graph the data in a reasonable manner and then interact with it by highlighting regions of interest and then finding out for example when the last full GC was or what the average time is between two young GCs or how much space on average is gained after a full GC in that selected time-frame. 

I suspect something like the dynamic 2D graphs that google finance uses would be sufficient to do most of this work, but I have never seen it used anywhere else before. So, does anyone know what I am talking about and how to go about implementing it?

Friday, February 12, 2010

Trying to use the Java plugin in Firefox

I've been trying forever to get the Java plugin to work on Firefox on Linux. There is an Ubuntu specific way to do it but I don't want to use apt to install it. My JDK is installed in /usr/local/jdk1.6.0_18.

So how do I do it? Used to be, you could go into the mozilla/plugins folder and you link the libjavaplugin_oji.so from the jre/plugins folder. Except no such file exists on my installation of the JDK. After searching on google and looking at official documentation from Oracle/Sun, I saw others have it... but not me. Turns out that my JDK is 64-bit and the setup is different. From one of the Oracle/Sun forums, I noticed that the name and path to the plugin are now different on the 64-bit version of the 1.6 JDK.

So, in my case, the plugin is located at
/usr/local/jdk1.6.0_18/jre/lib/amd64/libnpjp2.so
and by creating a symbolic link to it in ~/.mozilla/plugins, I have access to the Java plugin now. I needed that to use webex on my Ubuntu machine.

Tuesday, April 28, 2009

How do I set JAVA_HOME in Ubuntu so it works

I recently installed Ubuntu 9.04. And then I installed eclipse. I am trying to start it from an icon (yes, its via an icon... don't judge!) and am having an issue with setting the JAVA_HOME and PATH variables correctly.

When I kick off from a bash shell, the PATH is correct. But not from the panel in gnome. Of course, in the bash shell, I have both those variables set in ~/.bashrc. However, when I log in via the gdm, that file does not get read. I am trying to figure out what file gets read when I login so I can set the JAVA_HOME variable. I tried adding it to /etc/environment file, but I am at a loss as to how to add $JAVA_HOME/bin to the $PATH variable. For now, I start eclipse via the icon using

/usr/local/eclipse -vm /usr/local/jdk1.6.0_13/bin/java
and that works just fine for me...

Do I need the Java EE editor to work with Tomcat

I am pretty certain that all I have at work is a regular Java IDE and I am able to muck about with Tomcat... mind you, I don't deploy anything onto Tomcat via a 'Server' option. So, how come I can't do that easily with my regular IDE? I tried to install the Java EE development patches via Eclipse and it threw an error at me. I've seen the same requirement for some glassfish tutorials I was following before.

Is it because of that 'Server' feature that I need the EE version of Eclipse? I don't mind installing it, I was just curious. Anyone know?

Saturday, January 31, 2009

Hello World BlackBerry Storm Style

As with any new development project, one starts off with a simple 'Hello World' application. And so it is with the BlackBerry and Java code on it. I had a bunch of trouble getting the BlackBerry Eclipse plugin to work properly with Eclipse, but after installing, un-installing and generally cursing the damn thing a few times, I got it to work. I think the big trick was to understand that there are 2 things one needs to install:
  • The BlackBerry JDE plugin for Eclipse and
  • The BlackBerry Component pack (4.5.0, though I was able to build for the 4.7 device...)
A separate post on getting the JDE plugin to work and some questions related to that shortly. For now, here's how I got Hello World to work... I followed the instructions from the Thinking Blackberry blog. Below are the screenshots on the 5930 device running the 4.7 OS. There is also the helpful video put out by the BlackBerry folks themselves that I used as well.