ERP 2.50:Developers Guide/Concepts/Servlet Structure
Contents |
Introduction
This document explains the current servlet hierarchy and structure in Openbravo ERP.
Class Hierarchy
HttpBaseServlet
Base class that extends from Sun's HttpServlet and implements ConnectionProvider interface. It contains all the methods to interact with the database connection pool. This class is part of Openbravo's core. Your servlet can extend from this class if you don't want authentication and authorization.
HttpSecureAppServlet
This class extends from HttpBaseServlet. The security of the application is implemented at this level. This class also contains common artifacts for things such as: render a JasperReport, Autosave implementation, Navigation history, etc.
MyCustomServlet
This is an example servlet class. All your servlets should extend from HttpSecureAppServlet if you want authentication and authorization mechanisms.
Example Servlet
MyCustomServlet Example
package com.somepackage.mymodule; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.openbravo.base.secureApp.HttpSecureAppServlet; import org.openbravo.base.secureApp.VariablesSecureApp; public class MyCustomServlet extends HttpSecureAppServlet { private static final long serialVersionUID = 1L; public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { VariablesSecureApp vars = new VariablesSecureApp(request); if (vars.commandIn("DEFAULT")) { printPageDataSheet(response, vars); } else pageError(response); } void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("This is MyCustomServlet"); out.close(); } }
doPost
Your servlet must override the doPost method with all the logic that you want to implement in the class. Generally you start with a new VariablesSecureApp object based on the request made. This object will contain all the data from the request, plus a lot of helper methods like commandIn(), etc. Your servlet should implement a "DEFAULT" action, that will be executed when no other command is passed to the servlet.
Languages: |
ERP 2.50:Developers Guide/Concepts/Middle Tier Fundamentals | ERP 2.50:Developers Guide/Concepts/XMLEngine