Tutorials : A Brief Introduction to Struts – Expression Language :

URL Related Tags:

URL related tags are commonly used in JSP pages to pass control to other pages, pass parameters to other pages, importing pages into a JSP page and to include content dynamically into a JSP page. The URL tags have a c:url and c:param tag to format and display URLs.

	<c:url value="http://www.somesite.com/welcome"  var="sampleUrl">
	<c:param name="param1" value="someVal" />
	<c:param name="param2" value="someVal2" />
	</c:url> 
	<a href=´<c:out value="${sampleUrl}">´ >Welcome </a>

The above code creates a hyperlink with the specified page and the parameters. The tag automatically takes care of the context path to the URL. Added to this the parameters are URL encoded to make sure they are not corrupted in transit. The URL tag supports URL rewriting if cookies are disabled on the client machine.

c:import is a useful tag if files or pages need to be imported into the current page. It is very similar to the include directive in JSP.

<jsp:include page="somePage.jsp">

However this tag is more powerful as it can help import from distant websites, hosts etc using http or ftp.

<c:import url="http://somewebsite.com/importThisFile.jsp" /> 

Most of the important and general purpose tags are already discussed above. These tags will be good enough to tackle the regular challenges in building a JSP page.

Advanced Tags

JSTL provides additional tag libraries for Formatting, Internationalization, XML manipulation and SQL functions. We shall briefly discuss them here.

Formatting is one of the functions provided by JSTL which allows numbers, text, time and dates to be displayed according to user preferences without being changed in the database or at the server side. The tag library automatically formats any given java.util.Date according to the date style, time style, pattern and time zone and displays it to the user.

Internationalization is another function provided by the JSTL. This helps in providing locale specific information without rewriting the application.

The JSTL provides a SQL tag library to deal with SQL related functions. When used in conjunction with Struts, using this tag library would be a violation of Struts, as Struts does not prefer to expose model layer business logic to the presentation layer. This library can be useful for simple one page websites that do not use struts and still need to display data from the database.

The XML library provides a wide range of functions to parse, iterate and transform XML files. The XML functions are based on XPath which is in turn a expression language for XML files.

Conclusion

Struts is a fantastic framework, many people would not dispute that statement but I don’t think the new tags are so friendly that even people with no programming experience can use them. That being said you can see the simplicity in the examples. I hope this brief introduction will encourage you to delve deeper into the Expression Language(JSTL). Details of the above libraries can be found in the final draft of the JSR 52 of the Java Community Process. Happy Coding!

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.