|
Novell eCommerce Beans Overview
Novell eCommerce Beans have been developed to facilitate Web application development. eCommerce Beans support any LDAP v2 or v3 compliant Directory so you can integrate your Web applications with any LDAP Directory. eCommerce Beans have been written to encapsulate a single task in one bean. The beans are simple to learn and implement. Here are some features you can add to your application using Novell eCommerce Beans:
- User Authentication
- User Profiling
- User Creation
- User Portal
- User Rights
- Secure Connections
All of the information can be stored in the Directory. With the ability to leverage the existing attributes already defined for objects in eDirectory and the ability to create additional attributes, eDirectory makes using Novell eCommerce Beans powerful, flexible, and easy to use. That is the real power of eCommerce Beans.
Web Programming
Web programming includes a variety of technologies from many vendors. In this course, I'll focus on how to integrate Web programming with Java Web technologies and architectures.
Architecture
Web Programming with Java offers a little different architecture than desktop application programming. In addition to a browser and HTTP requests, we have a Java Application server that works together with the Web server to service requests for Web applications. The following diagram illustrates a commonly used Web programming architecture.
Figure 2:
Model View Controller (MVC) architecture.
This architecture is referred to as the Model View Controller (MVC) architecture. The MVC architecture is a logical representation of how to implement a Java Web application. It is a conceptual architecture. Each component represents a function in the architecture. In Figure 2 I have labeled the common Web implementations of each component.
Model-- The model is the datastore of the application. It is where the information the user is seeking is stored. The other components are the interface for the user to request and receive the information that is stored in the model. In a Web environment, we typically use a database or a Directory. The implementation of the model in our example is eDirectory.
Controller-- The controller component is the "engine" of the architecture. It queries or updates the model for information and controls the flow of information back to the user. It will most often provide the user interface as well. The implementation of the controller in our example is a Java Servlet.
View-- The view component displays information from the model to the user. The model must communicate with the view so that information is always current. The implementation of the view in our example is HTML. It could also be straight HTML, JSP, XML with XSL, or another display technology.
Technologies
In order to completely understand the power and flexibility of the Model View Controller architecture, you should be familiar with the J2EE technologies Java Server Pages (JSP) and Java Servlets.
Java Servlets-- For convenience I will only talk about the HttpServlet. Java Servlets are Java's answer to CGI. Java Servlets are a Java class that extends the Servlet API. Java Servlets are used to process information. They can easily receive information from a Web page or applet and then process that information by querying or updating the datastore for the application. The servlet can maintain connections to a database or Directory. A servlet gives a programmer the advantages of a fully functional Java API and also the ability to output content to a static Web page using HTML or other Web display technology. Simply put, a servlet is Java code with HTML embedded within it.
Some advantages of using Java Servlets are:
Portability-- Servlets have the portability of Java. With little or no modifications, a servlet can be compiled and deployed for multiple servers.
Powerful-- Unlike applets, servlets do not have the same security restrictions because the processing happens on the server. Servlets are not executed on the client --so you have a fully developed Java API to leverage.
Performance-- Servlets are multi-threaded by default which offers better performance than CGI since CGI scripts open a new process for each connection.
A servlet is an excellent solution for data processing. It can receive data, process it, and request data from other sources easily and provide excellent performance as well. It is more work to provide a complex display in a servlet. A servlet is great for information processing, but it is more work if you want to display the data in a fancy way. If you have data processing to do as well as render a complex HTML page, you may want to consider using JSP.
In order to run a servlet, you will need a Java Application server that will process the servlet. An application server works with the Web server to process the requests for Java Web applications. Examples of Java Application servers are Apache Tomcat, BEA WebLogic, IBM WebSphere, and SilverStream Application Server.
To deploy a servlet, you should copy the .class file to the specified directory on the Java Application server and then restart the server. You will then be ready to access your servlet.
Frequently, your servlet will only be a part of a larger J2EE archive file such as a CAR/WAR/EAR file. In this case, copy the archive file to the specified directory and restart the application server.
To access your servlet, type in the fully qualified URL to the server including port number and the path to the servlet. If you choose the default deployment directory, the URL will most likely have the servlet path before it. The default port is 8080, but can be changed to a different port. For example, in order to access a servlet called Servlet1, on the server AppServer.Novell.com, type the following URL: http://www.AppServer.Novell.com:8080/servlet/Servlet1.
Below is sample code from a basic "Hello World" servlet.
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class helloservlet extends HttpServlet { private static final String CONTENT_TYPE = "text/html"; public void init() throws ServletException { } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Hello World Servlet</title></head>"); out.println("<body bgcolor=\"#ffc800\">"); out.println("<h1>"); out.println(request.getParameter("name") + " says Hello World!!</h1>"); out.println("</body></html>"); } public void destroy() { } }
This servlet relies on the HTML page with a text box called "name" that submits the contents of the text box to the servlet. In order to do this, the <form> tag attributes need to be:
<form action="HTTP://host_name:8080/servlet/helloservlet" method="post">
JavaServer Pages (JSP)
JavaServer Pages are an extension of Java servlets. Essentially, JSP is the reverse of a Java servlet. JSP is an HTML page with embedded Java code inside to provide the dynamic functionality to the Web page.
JavaServer Pages also require an application server in order to run. The application server actually compiles the JSP into a Java Servlet.
A JavaServer Page is deployed by copying the .jsp file to the application server directory just as with servlets. When the page is invoked from a browser, the JSP will display itself. Take a look at this sample JSP and notice how the JSP is the reverse of a Java servlet. You can use native HTML tags and the Java code is marked by the <% and %> signs. The advantage of JSP over servlets is that you have an easier HTML design capability instead of having to write an out.println() statement for every tag you need.
<HTML> <HEAD> <TITLE>Hello World JSP!!</TITLE> </HEAD> <BODY> <% out.println(response.getParameter("name"));%> says Hello World! </BODY> </HTML>
Just like the Java servlet, this JSP relies on an HTML page with a text box called "name" that will post the information to this JSP.
JSP works well when you have a more intensive display to render than a Java servlet. JSP gives you the advantage of information processing together with the easy ability to display the information in an attractive way to the user. For example, if you have a complex HTML page to display, you would probably want to use JSP because it is easier to code and test the HTML in JSP.
JSP and JavaBeans can be used together to easily provide a powerful dynamic Web application.
|