Thursday, July 24, 2008

Struts Magic

Had a recurring problem in struts app - passing attributes from one action to another by forward is getting lost, here is a solution : redirect="true" should solve the issue. http://strutscollections.blogspot.com/2008/02/action-chaining.html

Tuesday, July 22, 2008

Speed typing tips.

Here are a some basic tips, summarized from various typing tutorials and lessons. These tips are useful for taking tests as well as everyday keyboarding:
  • Tap on each key crisply but lightly. If you use minimum force (don't bang on the keys), your fingers will move faster.
  • Type as quickly as you are able, but don't "try" too hard or force your speed or you'll make many mistakes.
  • Relax!
  • Use proper posture, sit upright.
  • Keyboard/monitor positioning: your wrist, elbows and keyboard should be on the same horizontal plane, and at a 90 degree angle to your upper arms.
  • The top of your screen should be near eye level.
  • Stretch your wrists and fingers before starting a typing test (don't laugh, it does help!).
Ref: http://www.calculatorcat.com/typing_test/

Friday, July 18, 2008

I love log4j

Logging is a very useful thing. Without this most of our java softwares are like black boxes.
The major problems we face is setting up the log4j. Also trying to decipher the cryptic clues is annoying, like say log4j WARNING No appenders could be found. Who has time to fix these issues..
Well it pays of well if you fix it as I said u cant fix a software problem without seeing what is happening inside. It will be like the movie HAPPENING(Should have been what is happening) ...


A few tricks to get the log4j setup:
Passing VM arguments
-Dlog4j.configuration=file:C:/development/projects/webapp/target/classes/log4j.properties

-Dlog4j.debug=true .....Excellent option to know what is happening inside log4j.


commonly used log4j.properties is below:
---------------------------------------------------------------------------------------------
log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
-----------------------------------------------------------------------------------------

More log  to come here...

Ref: http://logging.apache.org/log4j/1.2/manual.html

Tuesday, July 15, 2008

Print request object using JSTL


        
<p>Headers</p>   
<c:forEach var="hdr" items="${header}">                           
<table bgcolor="lightgreen">
    <tbody>
        <tr>
            <td>
                <c:out value="${hdr.key}">
                </c:out>
            </td>
            <td> 
            <c:out value="${hdr.value}">
            </c:out>
            </td>
        </tr>
    </tbody>
</table>
</c:forEach>
        
        
<p>Attributes:</p>

        
        
<c:forEach var="attr" items="${pageContext.request.attributeNames}">                         
<table bgcolor="lightgreen">
    <tbody>
        <tr>
            <td>
                <c:out value="${attr}"> </c:out>
            </td>
        </tr>
    </tbody>
</table>
</c:forEach>
        
        
<p>Parameters</p>

        
        
<c:forEach var="pmtr" items="${pageContext.request.parameterMap}">                          
<table bgcolor="lightgreen">
    <tbody>
        <tr>
            <td>
                <c:out value="${pmtr.key}"> </c:out>
            </td>
            <td> 
            <c:out value="${pmtr.value}">
            </c:out>
            </td>
        </tr>
    </tbody>
</table>
</c:forEach>

Monday, July 14, 2008

Working with microsoft DLL,ODBC connection and IIS for a java developer

DLL's are dynamic link library. They are like .jar files in java.
Normally the error we get in dll's are due to dependency on other dll's. Tools like dependency walker and dll explorer come for the rescue.

To register a dll use(like loading jars to JVM)
regsvr32 [DLL path]

also
rundll32 [dll path]

IIS
  • IIS is web server provided by microsoft.
  • For the IIS we need to configure the components.
  • For this, go to control panel-- admin tools --computer mgmt --component services -- computer--my computer -- COM+ applications -- new application --Add users and imports ...Thats it the IIS will pick it up...

To unit test a package in the dll create a x.vb file with the below code:

set testobj = nothing
set testobj = createobject("IMPORT.Job")

msgbox "PR: " & testobj.PathRemoved("C:\development\miscellaneous\COM\testmdb")

if(testobj.DeleteFile ("C:\development\miscellaneous\COM\test.mdb"))Then
msgbox "Deleted your file!"
End if



--------------------------------------------------------------------------------------------------------------
Oracle connection through microsoft:

update \oracle\product\10.2.0\client_1\NETWORK\ADMIN\tnsnames.ora
Go to control panel-- datasourc(ODBC) connections --add new connection in first tab.Select database name and auth details.Do a test connection. Thats it

-----------------------------------------------------------------------------------------------------------------

I need to set a number of environment variables via a bat file currently I m executing as below.
The user environment variables are updated but I want to set the system ones, what do I have to do.
Also when I try to add paths to the path variable I get an error
@echo on
setx IT_CONFIG_DOMAINS_DIR=C:\Program Files\IONA\etc\domains
setx IT_DOMAIN_NAME=BankWorld
setx IT_LICENSE_FILE=C:\Program
Files\IONA\etc\Orbix_licenses.txt
setx IT_PRODUCT_DIR=C:\Program Files\IONA
setx PATH=%PATH%;C:\Program Files\IONA\bin;C:\Program Files\IONA\asp\6.3\bin
pause
:end
pause

How about using the -m switch?
setx IT_CONFIG_DOMAINS_DIR=C:\P
rogram Files\IONA\etc\domains -m
setx path "%path%;c:\new directory"



Using Cygwin
Where is my windows drive? Ans: inside cygdrive<br />bash$ cd C:/Windows<br />bash$ pwd<br />/cygdrive/c/Windows</pre><br /><b>IIS<br />Changing the default port:<br /></b><table class="list ol"><tbody><tr><td class="number"><small><small></small></small></td></tr><tr><td class="number"><small><small></small></small></td></tr></tbody></table><small><small>Microsoft Internet Information Services versions 4.0 to 6.0</small></small><script type="text/javascript">loadTOCNode(2, 'moreinformation');</script><table class="list ol"><tbody><tr><td class="number"><small><small>1.</small></small></td><td class="text"><small><small>Open Internet Service Manager or Internet Information Services (IIS) Manager.</small></small></td></tr><tr><td class="number"><small><small>2.</small></small></td><td class="text"><small><small>If necessary, expand the Web server that you want, and then expand <b>Web Sites</b>.</small></small></td></tr><tr><td class="number"><small><small>3.</small></small></td><td class="text"><small><small>Right-click the Web site that you want to change.</small></small></td></tr><tr><td class="number"><small><small>4.</small></small></td><td class="text"><small><small>Click <b>Properties</b>.</small></small></td></tr><tr><td class="number"><small><small>5.</small></small></td><td class="text"><small><small>Click the <b>Web Site</b> tab.</small></small></td></tr><tr><td class="number"><small><small>6.</small></small></td><td class="text"><small><small>Change the TCP Port Number in the <b>TCP Port</b> edit box (or click <b>Advanced</b> for multiple Port settings).</small></small></td></tr><tr><td class="number"><small><small>7.</small></small></td><td class="text"><small><small>Click <b>OK</b> to save the changes.</small></small></td></tr></tbody></table><br />Ref:<br /></div><small>Environment variable excellent reference : http://www.wilsonmar.com/1envvars.htm<br />IIS port change ref: http://support.microsoft.com/kb/149605<br /><br />IE browser issues<br />Having made a web application live, the user logoff action doesn't actually log off in IE. It works fine on firefox.. So the problem is obviously with the browser. Crap the microsoft IE doesn't handle caching well inspite of setting the pragma in the head tag. You need to put it in the bottom of the page as well.<br />Put the following in top and bottom under html tag<br /><pre><br /><head><br />   <meta http-equiv="cache-control" content="max-age=0, must-revalidate, no-cache, no-store, private"><br />   <meta http-equiv="expires" content="-1"><br />   <meta http-equiv="pragma" content="no-cache"><br /></head><br />

Here is the fix.
http://support.microsoft.com/kb/222064/

http://www.vbaccelerator.com/insprob.htm







Saturday, July 12, 2008

linux mysql setup quick start

To summarize ,

3306 default port of mysql

Login as root.

Start the database: /etc/rc.d/init.d/mysqld start

Databases located in: /var/lib/mysql/
Default config file installed by RPM: /etc/my.cnf

The first task is to assign a password:

[prompt]$ mysqladmin -u root password 'new-password'

Create a database: (Creates directory /var/lib/mysql/bedrock)

[prompt]$
mysqladmin -h localhost -u root -ppassword create bedrock
(or use SQL command: CREATE DATABASE bedrock;)

Add tables, data, etc: Connect to database and issue the following SQL commands:

[prompt]$
mysql -h localhost -u root -ppassword
...
mysql>
use bedrock; - Define database to connect to. Refers to directory path: /var/lib/mysql/bedrock
mysql>
create table employee (Name char(20),Dept char(20),jobTitle char(20));
mysql>
DESCRIBE employee; Shutting down the database:

[prompt]$
mysqladmin -u root -ppassword shutdown - PREFERRED
OR
[prompt]$
/etc/rc.d/init.d/mysqld stop
OR
[prompt]$
service mysqld stoplt;/b> mysqladmin -h localhost -u root -ppassword create bedrock

Ref:
http://www.yolinux.com/TUTORIALS/LinuxTutorialMySQL.html

Wednesday, July 9, 2008

Maven - an expert .

Basics set MAVEN_HOME mvn install mvn clean install mvn package -Dmaven.test.skip=true mvn surefire-report:report mvnrepository.com It downloads the repository to c:\Documents and Settings\[USER]\.m2\repository Intermediate Setting up maven based projects into eclipse Eclipse needs to find the Maven-downloaded jars for compilation. Under Preferences > Java > Build Path > Classpath Variable M2_REPO should be set to ..\.m2\repository Run mvn eclipse:clean --- dletes .class and .project files mvn eclipse:eclipse --- creates .class and .project files using pom.xml (recursively) Thats it. Advanced Steps to create an archetype project: Use below to create a sample archetype meta project. />mvn archetype:create -DgroupId=[com.biomedcentral] -DartifactId=[archetype-spring-jar] -DarchetypeArtifactId=maven-archetype-archetype Update the archetype [archetype-spring-jar]\src\main\resources\META-INF\maven\archetype.xml Keep all the relevant resource in the [archetype-spring-jar]\src\main\resources\archetype-resources\... and update the archetype with its reference. Install the archetype project itself: />mvn install Now time to use this project generator: mvn archetype:create -DarchetypeGroupId= -DarchetypeArtifactId= -DarchetypeVersion= -DgroupId= -DartifactId= This is amazing...From an existing architecture u can clone yours ... A sample command using above for spring hibernate is below: #mvn archetype:generate -DarchetypeGroupId=com.webtide -DarchetypeArtifactId=maven-archetype-SpringJpa -DarchetypeVersion=1.0 -DgroupId=c om.my.package -DartifactId=ImageLibraryCategoryManager mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create -DgroupId=com.my -DartifactId=springmvc-hibernate-app -DarchetypeArtifactId=appfuse-basic-spring -DarchetypeGroupId=org.appfuse.archetypes A bit on Maven Plugins: 1. maven-dependency-plugin : http://maven.apache.org/plugins/maven-dependency-plugin/ Very useful for copying dependency jars for a standalone app,etc. Reference: http://mevenide.codehaus.org/ -- plugin for eclipse http://maven.apache.org/guides/mini/guide-attached-tests.html http://www.webtide.com/resources.jsp --samples For springmvc-hibernate archetypes use http://docs.codehaus.org/display/MAVENUSER/Archetypes+List http://maven.apache.org/guides/mini/guide-creating-archetypes.html Debug maven : http://tech.puredanger.com/2009/02/25/maven-tips/