Friday, June 5, 2009

JSTL

What is JSTL?

The JavaServer Pages Standard Tag Library (JSTL) encapsulates, as simple tags, core functionality common to many JSP applications. For example, instead of suggesting that you iterate over lists using a scriptlet or different iteration tags from numerous vendors, JSTL defines a standard tag that works the same everywhere.

You can also download JSTL taglib library from Jakarta apache project online website on http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/binaries/. Some included jar for JSTL 1.1 library are jaxen-full.jar, jstl.jar, saxpath.jar, standard.jar, xalan.jar. However, only jstl.jar and standard.jar are required.


How to Install JSTL:
1. Download jstl.jar and standard.jar
2. Put those two jar files into /common/lib/ in your Tomcat directory
(All the application under Tomcat will share those jar files inside common/lib/)
3. Below is how your code will looks like if you want to make use of JSTL in your JSP file:





Other taglib that will be used in creating dynamic webpage

We are going to download struts-taglib.jar file. Here is the website where we can find most of the jar files: http://www.java2s.com/Code/Jar/CatalogJar.htm

1. Download the strits-taglib.jar file from that website.
2. Extract the jar file
3. After the jar file has been extracted, you will fid two folders, such as: META-INF and org.
We only care about the META-INF. Open the META-INF and you will find the 'tld' folder.
The files inside the 'tld' folder: struts-bean.tld, struts-html.tld, struts-logic.tld and struts-
nested.tld

Now we will look at the struts-bean.tld.

First, create new folder 'tlib' in your WEB-INF/ directory of your Struts Application. Mine is located here C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\struts2tutorial\WEB-INF\tlib
Copy the struts-bean.tld into tlib folder.

You will need to add struts-taglib.jar file into the /common/lib/ directory of your Tomcat and use your Eclipse - Porject properties to add struts-taglib.jar.



2.

Thursday, June 4, 2009

Configuring the STRUTS application in Eclipse Version 3.4.2

Configuring the STRUTS application in Eclipse Version 3.4.2
1. Open new Java Project
2. Choose 'Create project from existing source' option. Click 'Browse' button.
3. Now, find your Struts appplication folder. (My Struts application location is C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/struts2tutorial/ ). Click OK.
4. Name your Project. Click 'Next'.
5. Click 'Finish' and your Struts application will be added to your Eclipse.
6. Now, we will build your Struts Application by using Ant Build.
7. From your Eclipse Package Explorer, select WEB-INF --> src. Right click the 'build.xml' and click 'Ant Build'.
8. Console tab will be displayed to show the progress of the application building.
9. If you encounter failure in building the application, such as you get error message 'build.xml:55: Error starting modern compiler', it means that you are using incorrect version of JRE.
10. To resolve issue in point. 9, make sure you install higher version of JRE. In my case, I will upgrade it from JRE 1.5 to JRE 1.6
11. After you have get your JRE 1.6, you need to installed in your Eclipse. To do this, read the point 12.
12. Go to 'Run' --> 'External Tools' --> 'External Tools Configurations' --> Open the 'JRE' tab.
- Choose the 'Seperate JRE' option and click 'Installed JREs' button.
- In the next screen, choose 'Standard VM' and click 'Next'
- Click 'Directory' button next to 'JRE Home' and select the root folder of your new JRE (1.6)
- Click 'Finish' and your JRE 1.6 will be added into Installed JREs list. Make sure you tick
the checkbox next to the JRE 1.6. Click 'Ok'.
- In the 'Seperate JRE' check box, make sure you select JRE 1.6. Click 'Apply'. Click 'Run'.
- You will see that your Struts will be built successfully.
Good Luck.. ^^

Tuesday, March 31, 2009

Developing Simple Program in STRUTS

Developing Simple Program in STRUTS 1.3.10
In this article, I will show you how to develop simple program called “MiniHR” by using Struts 1.3.10.

Requirements:
1. Java SDK 1.6
2. Struts 1.3.10 (
http://struts.apache.org/download.cgi ). Download the Full Distribution.
3. Apache Ant 1.7.1 (http://ant.apache.org/bindownload.cgi ). Download the .zip archive.
4. Apache Tomcat 5.5.17(
http://software.emule.com/apache-tomcat-5-5-17/ )


Installation Guide:
1. Install Java SDK 1.6 . In my case, I install in “C:\Program Files\Java”

2. Create a new record under System Variables in your Environment Variable.
    Variable: JAVA_HOME
    Value: C:\Program Files\java

3. Extract the Struts 1.3.10 into your harddisk. In my case, I copy to my “C:/Program Files” folder.
4. Extract Apache Ant 1.7.1 into your harddisk. In my case, I copy to my “C:/Program Files” folder.
5. Create a new record under System Variables in your Environment Variable.
    Variable: ANT_HOME
    Value: C:\Program Files\apache-ant-1.7.1


Below are files that needed to built our MiniHR program:

File

Description

index.jsp

Contains the JSP that is used as a gateway page for the Mini HR application and provides a link to the Employee Search Page

search.jsp

Contains the JSP that is used for performing employee searches and displaying the search result

SearchForm.java

Contains the class that captures and transfer data to and from the Search Page.

SearchAction.java

Contains the class code that processes requests from the Search page.

EmployeeSearchService.java

Contains the class that encapsulates the business logic and data access involved in searching for employees.

Employee.java

Contains the class that represents an employee and encapsulates all of an employee’s data.

web.xml

Contains the XML that is used to configure the servlet container properties for the Mini HR Java Web Application

struts-config.xml

Contains the XML that is used to configure the Struts framework for this application

MessageResources.properties

Contains properties that are used to externalize application strings, labels, and messages so that they can be changed without having to recompile the application.


Followers