Alfred’s Computing Weblog

Alfred Java-cored Computing Weblog

Struts1 | Forward Page

leave a comment »

This is a simple and quick solution to forward / go to a page in struts1.

In normal case, we have to call to a class extending ActionForm before you’re going to the next JSP page. For cases that you do not need any action to perform before you reach that JSP, you can call the class org.apache.struts.actions.ForwardAction. So that, you only have to prepare the JSP file and do the configuration in struts-config.xml as below.

<action-mappings>
    ....
    <action path="/ForwardLogin"
        parameter="/WEB-INF/pages/login/login.jsp"
        type="org.apache.struts.actions.ForwardAction"
        scope="request"
        validate="false"/>
    ....
<action-mappings>

Written by Alfred

June 19, 2009 at 15:28

Posted in Struts1

Tagged with ,

Disable BEEP sound in Terminal

leave a comment »

I’m not sure this is the best solution or not, but its work!
This is an output of my google when I want to disable the error beep sound in terminal.
The beep sound I’m talking about is the annoying sounds like
“beep” or “tuuu” when you’re over pressing backspace or type something wrong in terminal.

The solution that I’m going to share here is COPY from netty5.
I feel that its very useful especially to those who is not familiar with terminal,
coz everything can be done by few mouse clicks.

1. Move your pointer to the top-left corner of your desktop.
2. Click on “Applications” > “Accessories” > “Terminal”. A terminal will be pop up.
3. On the Terminal, click on “Edit” > “Profiles..”. A small windows named “Profile” will be pop up and a “Default” profile is selected by default.
4. Click on “Edit” in the Profile window. Another small window will be pop up.
5. Click on “General” tab, UNCHECK the “Terminal bell”, and close all poped up windows. And you’re done. no more “beeeep” or “tuuuuu” sounds :)

FYI, I’m using Ubuntu 9.04 at the moment.

Written by Alfred

June 16, 2009 at 18:36

Posted in linux

Tagged with , , ,

Java | How to access Enum’s public method?

leave a comment »

Enum is an enumerated types, a special type in Java that used to hold static information.
Eg: the state of a connection (CONNECTING, CONNECTED, DISCONNECTED, etc), the day (MONDAY, TUESDAY, etc).
Besides of defining a status, we also can include some useful features of the Enum and write it as a method in the Enum.
Here is a simple example I write to show how to access to Enum’s method.

I have a Enum here, named “Day”:

package alfred.playground;

public enum Day {

	MONDAY, TUESDAY,
	WEDNESDAY, THURSDAY,
    FRIDAY, SATURDAY,
    SUNDAY;

	public boolean isWeekday() {
		return (equals(MONDAY) ||
				equals(TUESDAY) ||
				equals(WEDNESDAY) ||
				equals(THURSDAY) ||
				equals(FRIDAY));
	}

	public boolean isWeekend() {
		return (equals(SATURDAY) || equals(SUNDAY));
	}

}

And, here is the test program:

		Day day1 = Day.THURSDAY;
		System.out.println(String.format("[%s] is weekend? [%b]", day1, day1.isWeekend()));
		/*$>  [THURSDAY] is weekend? [false] */

		Day day2 = Day.SATURDAY;
		System.out.println(String.format("[%s] is weekend? [%b]", day2, day2.isWeekend()));
		/*$>  [SATURDAY] is weekend? [true] */

In order to call Enum’s method, we can not just directly call as usual class’s method “myClass.doSomething()”.
Instead, we must assign a value to the Enum before we can invoke the method.

For shorter codes, we can simplified the code by skipping the value assignment line:

		System.out.println(String.format("[%s] is weekend? [%b]", Day.FRIDAY, Day.FRIDAY.isWeekday()));
		/*$>  [FRIDAY] is weekday? [true] */

Written by Alfred

April 2, 2009 at 16:27

Posted in Java

Tagged with ,