Doing a Page Redirect from a Java Struts2 Action Class

Share this:  


I began working on a web site written in Java using Struts2. I wrote a general purpose class to be used by the application. One method in the class was supposed to check if the user was logged in. If not, redirect to the logon page (I did NOT want to add a tag entry to every <action> block in the struts.xml file)!

I searched the web and did not find anything that worked quite right. Finally, after some experimentation, I got something working! Here is some sample code for you:

Helper Class

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.*;
import javax.servlet.http.*;

public class myExample {
   public void doARedirectToGoogle() {
      HttpServletResponse response = ServletActionContext.getResponse();
      try {
      } catch (IOException e) {
      } // end of try / catch
   } // end of doARedirectToGoogle() method
} // end of myExample class

Note the try/catch block must be in place in order for this to compile and work.


Struts2 Action Class:

import com.chomer.demo;

public class demoPage extends ActionSupport {
   public String execute() {
      myExample demo = new myExample();
      return "success";
   } // end off execute() method
} // end of demoPage class


Action Block added to struts.xml:

<action name="demoPage" method="execute" class="com.chomer.actions.demoPage">
   <result name="success">/pages/demoPage.jsp</result>
   <result name="error">/pages/demoPageErr.js</result>


Success Page… demoPage.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
      <h1>This page will come up if the redirect does not work!</h1>


Failure Page… demoPageErr.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
      <h1>This page will come up if the redirect does not work AND there was an error!</h1>

In the above example I made up some arbitrary packages names. You will have your own structure in place. If this works you should never see the success or failure page.

In a real world scenario, the redirect would having only if a certain condition was being met (such as the user is not logged in). If the user were logged in, demoPage.jsp’s contents would appear.

“I Lost My Underwear” App Version 2 Has Been Released to Apple App Store

Share this:  

So far, the only app I have ever finished and placed in the App Store is not my own app. It is an app I have written for a friend. He wrote a book of humorous poems with illustrations called “I Lost My Underwear Today and other flights of imagination.” You can find this book for sale on Amazon. He asked me to create an interactive version of the book as an app for the iPad. This is when the iPad was brand new!

Now I have finished version 2. Not only does it run on the iPad, but the iPhone and iPod Touch as well. It now has little splashes of color, some sound effects, and the page turning looks like you are turning pages in a book as opposed to flipping pages of a legal pad (which is what it looked like in version 1).

So, it is out in the app store and I know that some people that I know have bought it and left reviews. So far, in the App Store, no sales show up nor any ratings or reviews are showing up. I wonder how long it takes before those things start to be visible.

Give it a try, its only 99 cents! :)

If you can leave some feedback below that would be very cool too.

Here is a link:

Time Off and Some Progress on my Own Blog Software

Share this:  

Yay! I am off until the end of the year! When it comes to vacation where I work its “use it or lose it!”

Blog Software
Its on Apache, using PHP, mySQL, and a .htaccess  file. After futsing about I got the .htaccess file doing what I want for my new blog software (I am no expert on this file by any means though).

The development environment is my iMac using MAMP. I’ve got it reading a site table in my mySQL database. This software will support multiple sites on one server!

Next I’ve got to look up how to use sub-string functions in PHP. I need to take the rootPath field value from my sites table and compare it with the beginning of the URI that the user typed in in their browser. If it matches, I will set the site id, if not, I want to have some sort of fall-out page.

Amazing Way to Remove PLA Prints from Build Platform

Share this:  

Ok, I own a Makerbot Replicator 2. It prints 3D objects in PLA plastic. Great! Cool! And so forth… One thing you notice if you own one of these machines is that the print sticks to the build plate with a kung fu grip. This is especially true of large prints. I can’t pry them off to save my life!

I’ve resorted to removing the build plate, then hitting the print with a rubber mallet. Sometimes I have to hit the print several times! Not good!

I read as much as I could find on the internet about this problem but the closest info I could find was for someone printing on a sheet of glass. They mentioned that if they let their printer cool down, the print would just pop off!

I tried that… even waiting over night! The print was still stuck really good… mallet time!

Then, yesterday evening I had an idea. Maybe cooling down to room temperature wouldn’t work for me… but what if I got the the print even cooler? Hmmm.

So, after my next big print, I removed the build plate with the print on it, tried to pull it off (stuck real good as ever) and tossed it in the freezer for a few seconds. I took it out of the freezer, gave it a twist with my bare hand and… Presto!  It popped right off! No struggling. No problem! For me this is huge!

Getting the print off usually would also pull on the surface I have on the build plate (right now a sheet of skinz).  This should remove or at least greatly reduce this problem.

I do not know yet if this works for ABS. I can’t do this with the Makerbot Replicator 2X since the build plate is not removable (I’m not going to stick the whole printer in the freezer)! Maybe if I clipped on a sheet of glass onto the build plate? :)

Anyways, I thought I would let you know.

Thingiverse Ornament Challenge Entered

Share this:  

I designed 3 entries in Sketchup, each building off the previous entry. The first entry was a single ornament designed to be printed in translucent PLA plastic. The next entry was that same ornament in a little box. And the final entry, a compartimental box with six of the same type of ornaments inside.

We’ll see if I am one of the finalists next Monday.

UPDATE: Tuesday, December 10…. still no word of who are the winners…

UPDATE: Wednesday, December 11… the winners have been announced. I am not one of them. :(  It was still fun! :)

PLA Printing Saga Continues

Share this:  

I did a print on my Makerbot Replicator 2 in True Yellow PLA filament. It was truly a bear to remove it from the blue painter’s tape covered build platform. The print actually split/cracked some as I tried to remove it! Not good! :(

I notice that to some extent, as the plastic shrinks, it starts lifting the painter’s tape up off the platform little by little. I am replacing the tape quite often.

I noticed when I went to the Microsoft Store and saw their demo printer printing thing that their printer’s build plate was covered with something different, and that they seemed to not be having the problems of their prints either not sticking or sticking way too much. Hmmm. So I went back to their store to ask some questions. It seems that they have been using a stick-on Skinz layer that sticks to the build plate and then trim it with a razor. The guy I was talking with said that it seems to last about a month for them. And… he gave me a sheet of the stuff to try out! :)

I have applied it my build plate! The logos printed on it are crooked and upside down… But do I care? No, I am not after fashion… I am after better success with my 3D Prints! I will let you know how this goes.

Getting PLA Prints to Stick Without a Raft

Share this:  

Printing in PLA on my Makerbot Replicator 2 with a raft is pretty reliable. There are a few problems with this though:

  • I waste extra filament on the material to print the raft.
  • Printing the raft gobbles up a lot of extra time for the print.
  • Getting the model detached from the raft can be really tough (this is the biggest problem by far).

So printing without a raft can be a good thing! The problem is getting the first layer to stick! Here are a few tips I have found helpful at this time:

  • Put a nice even layer of blue painter’s tape on the build plate.
  • Make sure you properly level the build plate.
  • Sand the surface of the blue painter’s tape with sandpaper.
  • Wipe down the surface of the blue painter’s tape with rubbing alcohol (this was important, before I did this parts of the print would not stick).
  • Set the printer’s print speed way down (notice how it prints the first layer of the raft real slow — 30mm per second). — note due to improvements in Makerbot’s software, this step is no longer needed.

This did it for me.

Of course setting the print speed real slow causes the print to take a whole lot longer. I wish Makerbot would change their Makerware software so that if you printed without a raft it would automatically print the first two layers really slow then print the remaining layers at the speed set by the user in Makerware.

Wishing for Memory Functions in JavaScript

Share this:  

At work I am working on a web app that is very data intensive. A whole lot is done on the client side in JavaScript. There are certain instances in tests I have done where I have run out of memory.

I can adjust parameters down until the errors go away but:

  • Am I getting the absolute best usage of my memory or am I “leaving my change on the table?”
  • What if a user’s PC has less memory than me, are they going to get out of memory errors?
  • What if a user’s PC has a lot more memory than I do… then they really will not be able to leverage that extra memory to their advantage.

I wish there were two JavaScript functions available for programmers to use:

  • totalMemory()
  • availableMemory()

The functions could be called something else, that’s fine. But if there were these functions and if they returned the number of bytes relative to what was accessible to that current instance of the web browser, that would be so useful! As far as I know, JavaScript does not have any functions like this. I’ve looked :)

Am I missing something? Are there functions or object properties that I’ve missed? If you are a web developer working on some data intensive stuff on the client side don’t you wish you had these functions available?

One More Memory Related Thing
One more thing regarding JavaScript memory usage… There is a piece of info that I do know is out there somewhere… but I have not found yet… How much memory do JavaScript variables use?

I assume strings  may use 1 byte per character (or do they use 2 bytes to support unicode). I assume booleans take the least amount of memory (possibly 1 bit)? There are integers and floating point values… how many bytes do they use each? What is the overhead number of bytes for each variable and for each element in an array? Knowing this information could be helpful in deciding how to store information in memory the most efficient way.

Microsoft says that their floating point variables in JavaScript use 8 bytes (search for the word “byte” on the page).

This looks like an interesting JS library: something where you pass in a variable or JSON string and it returns how many bytes it takes up.  I have to investigate this further when I have some time!

Crazy Ways of Designing 3D Printed Parts

Share this:  

So I got my female connection test piece working perfectly. My thought was Yes! I now have the measurements I need  to implement connections on the actual model!

Not so fast. I guess I just do not have the hang of this.  It seems to involve a lot of trial and error. Like I’ve said before, I am using Sketchup to design my parts.  This part of the project is driving me nuts. Its just the first part… getting the four base pieces to snap together.

I did not work on it last night because I was just too frustrated with it.

Working on Test Connector

Share this:  

Yesterday evening I started working again on the design of a female connection piece. The model I am working on (which I want to make copies of and give as gifts to family members) will use these connectors on the base. Instead of just trying to add them to the main model right away, I am creating a small connector which I can adjust the measurements of and print in a relatively short period of time and test to see if it fits the male part of the connector.

If it does not, I can make adjustments to the measurements and repeat the process. Printing this test piece takes much less time than printing the whole actual part of the model! Once I get it just right I will write down the final “correct” measurements and use them for all the base pieces of the model.

A couple months back I was working on this test connector. I was printing test prints in ABS plastic. I am putting ABS aside and printing my tests in PLA plastic. It takes about 24 minutes to print my female connector test print on my Makerbot Replicator 2 3D Printer.

1 2 3 11