Tip

Java Server Page Tag Libraries and SAP

Author Jeff Marin is director of training and education at Gamma Enterprise Technologies, Inc.

SAP says its next generation of Web Application Server will be able to run ABAP and Java code side by side. Web Pages will be generated from SAP

    Requires Free Membership to View

BAPIs and RFCs. This will be accomplished with Java Server Pages (JSPs).

Java Server Pages are HTML files with Java code sprinkled in them. The HTML appears as normal text while special tags surround the Java code. These tags include <% and %> or <%= and %>. The Java code allows the page to be dynamic. For example, the following JSP file will display a greeting followed by the current time. Each time this Web page is viewed, the current time will have changed.

<html><body>Good Morning.  The time is <%= new Date() %></body></html>

As we want to accomplish more dynamic behavior with our JSP file, we need to add more Java Code. For example, the following JSP file connects to a database and displays the information from one of its tables.

Life Without Tag Libraries

<%@ page import="java.sql.*" %>

<html><body>
Contractors in database:<br><br>

<%
  Connection conn = null;
  try {
    Class.forName("COM.cloudscape.core.JDBCDriver").newInstance();
    conn = DriverManager.getConnection("jdbc:cloudscape:d:\\timereporterDB");
    Statement stmt = conn.createStatement();
    ResultSet resultSet = stmt.executeQuery("SELECT LOGINNAME, ID FROM CONTRACTOR");
		  
    while (resultSet.next()) {
%>

    LoginName:<%=resultSet.getString(1) %> ID:<%= resultSet.getString(2) %><br>

<%			
    }
  } catch (Exception e) {
    System.out.println(e.toString());
  } finally {
    try {
      conn.close();
    } catch (Exception e2) {
      System.out.println(e2.toString());
    }
  }
%>	   
</body></html>

As you can see, when inter-disbursing Java and HTML, things can get complicated very quickly! This is where JSP Tags come in. JSP Tags allow us to put more functionality in a JSP file without adding more Java code. Looking at the previous example, if we have a JSP tag or set of tags that can handle the behavior associated with connecting and communicating with a database we could use these tags in a JSP file like so:

Life With Tag Libraries

<%@ taglib uri="http://jakarta.apache.org/taglibs/dbtags" prefix="sql" %> 

<html><body>
Contractors in database:<br><br>

<sql:connection id="conn1">
  <sql:url>jdbc:cloudscape:d:\\timereporterDB</sql:url>      <sql:driver>COM.cloudscape.core.JDBCDriver</sql:driver> 
</sql:connection> 

<sql:statement id="stmt1" conn="conn1"> 
  <sql:query>SELECT LOGINNAME, ID FROM CONTRACTOR</sql:query> 
  <sql:resultSet id="rset2"> 

   LoginName:<sql:getColumn position="1"/> ID:<sql:getColumn position="2"/><br>

  </sql:resultSet>
</sql:statement> 

<sql:closeConnection conn="conn1"/>

</body></html>

Because JSP files are really HTML files with Java code added, Web Developers usually create them. Web Developers usually are not programmers in the strict sense of the word and have little or no experience with formal programming languages such as Java. However, they do excel in laying out and presenting Web pages from an artistic and business sense. JSP Tags and collections of tags, referred to as libraries, allow Web Developers to access the powers of Java without formal training in the language.

Where Can I Get A Tag Library?

You might be wondering where tag libraries come from. Actually, there is a lot of work being performed in the open source world by the same organization that created the world's most popular Web server, Apache. The Jakarta Project has created many tag libraries for all types of programming tasks including database access, benchmarking applications, and dealing with times and dates. Visit http://jakarta.apache.org/taglibs/index.html to find out more about these tag libraries.

Besides The Jakarta Project, many other tag libraries are available and are usually bundled with J2EE Application Servers. BEA's WebLogic Server, IBM's WebSphere, and Macromedia's JRun all come with their own versions of tag libraries to help solve routine programming tasks for Web Developers. Also, Java Developers can create new JSP tags and libraries of tags using the Java programming language.

JSP Tags and SAP

As I mentioned in the beginning of this article, Web Application Server 6.2 will allow Web Developers to access SAP functionality through JSP Tags. SAP will supply libraries of JSP Tags to access BAPIs and RFCs. Web Developers will use these tags to bring the power of SAP to the Internet without needing a formal education in Java.

Unfortunately, the first version WAS 6.2 will probably not be available until 2Q02 and organizations should probably not deploy on WAS 6.2 before 2Q03. If done correctly, SAP will have a powerful tool that should prove to be quite a productivity boost to Web-enabling your SAP applications.

Author Jeff Marin is director of training and education at Gamma Enterprise Technologies, Inc., and the author of "J2EE vs. .Net." Jeff is responsible for the growth of Gamma's Learning Center. The company provides software solutions to create, deploy and optimize critical business applications. Gamma is a technology partner with SAP.

Comments? Ideas? Send us an email at tips@searchsap.com.


This was first published in February 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.