### Creating and getting instances of RptServer or HttpRptServer

You can use the following three methods to get the instances of RptServer or HttpRptServer. Note that only one server can exist in the system, and in most circumstances, you should get the server instance instead of creating a new one.

#### Method 1

Use the method jet.server.api.http.HttpUtil.initEnv(Properties props).

The method jet.server.api.http.HttpUtil.initEnv(...) creates and initializes the HttpRptServer object. If the HttpRptServer has already been started, it will use the existing HttpRptServer instance. Use this method to avoid creating more than one HttpRptServer instance.

    //prepare report server initial properties.
    //The property reporthome must be set. For example: c:\JReport\Server.
    //Other properties are optional. They are:
    //jrs.isMyServer: Indicates if the HTTP server is JReport standalone server.
    //The default value is "false".
    //temp_dir or jrs.dir.temp: The path of temp directory.
    //The default value is <reporthome>\temp.
    //history_dir or jrs.dir.history: The directory where all the versions
    //of report set results will be maintained.
    //The default value is <reporthome>\history.
    //auth_scheme: It specifies the scheme of authentication.
    //Its value must be Basic or Digest.The default value is Basic.
    //default_doc: The home page of JReport Enterprise Server
    //It is an HTML file. If it is not set or the file set to it cannot be loaded,
    //the default home page of JReport Enterprise Server will be used.
    //The path is relative to <install_root>, for example, docs/index.html.
    //isConvertedServletPath: This property specifies whether your web server
    //decodes the path if it contains special characters.
    //This information is used for JRServlet to determine whether it needs
    //to convert that path. If you don't specify this property, your web server
    //is not supposed to decode the path.
    //vError: Enables JReport Engine to output messages to a file and sets all
    //log files' trace levels to OFF and error levels to ERROR.
    //vDebug: Enables JReport Engine to output messages to a file and sets all
    //log files' trace levels to INFO and error levels to WARN.
    //Properties props = System.getProperties();
    //get an initialized instance of HttpRptServer
    HttpUtil.initEnv(props);
    //also can get the instance of HttpRptServer by using
    HttpUtil.getHttpRptServer()
    // after called HttpUtil.initEnv(props)
    jet.server.api.http.HttpRptServer httpRptServer = HttpUtil.getHttpRptServer();
    //demo cast HttpRptServer to RptServer
    jet.server.api.RptServer rptServer = httpRptServer;

#### Method 2

Call the method HttpUtil.checkLogin(HttpServletRequest req, HttpServletResponse res).

The method jet.server.api.http.HttpUtil.checkLogin(...) implicitly calls HttpUtil.initEnv(...) if necessary. So you can get the HttpRptServer after calling HttpUtil.checkLogin(...).

    // check login at first
    if (HttpUtil.checkLogin(request, response))
    {// get the instance of HttpRptServer
    jet.server.api.http.HttpRptServer httpRptServer = HttpUtil.getHttpRptServer();
    // do something
    }

#### Method 3

Directly create an instance of HttpRptServer.

Demo 1:

    //create an instance of HttpRptServer jet.server.api.http.HttpRptServer
    //httpRptServer = new jet.server.jrserver.http.JRHttpRptServer();
    //initialize the HttpRptServer.
    //The property reporthome must be set.
    //For example: c:\JReport\Server.
    //Other properties are optional. The properties are:
    //jrs.isMyServer: Indicates if the HTTP server is JReport standalone server.
    //The default value is "false".
    //temp_dir or jrs.dir.temp: The path of temp directory.
    //The default value is <reporthome>\temp.
    //history_dir or jrs.dir.history: The directory where all the versions
    //of report set results will be maintained.
    //The default value is <reporthome>\history.
    //auth_scheme: It specifies the scheme of authentication.
    //Its value must be Basic or Digest.The default value is Basic.
    //default_doc: The home page of JReport Enterprise Server. It is an HTML file.
    //If it is not set or the file set to it cannot be loaded,
    //the default home page of JReport Enterprise Server will be used.
    //The path is relative to <intall_root>, for example, docs/index.html.
    //isConvertedServletPath: This property specifies whether your web server
    //decodes the path if it contains special characters.
    //This information is used for JRServlet to determine whether
    //it needs to convert that path. If you don't specify
    //this property, your web server is not supposed to decode the path.
    //vError: Enables JReport Engine to output messages to a file and sets all
    //log files' trace levels to OFF and error levels to ERROR.
    //vDebug: Enables JReport Engine to output messages to a file and sets all
    //log files' trace levels to INFO and error levels to WARN.
    //at least the property reporthome should be set.
    httpRptServer.init(System.getProperties());
    httpRptServer.start();

Demo 2:

    //create an instance of RptServer
    jet.server.api.RptServer rptServer = new jet.server.jrserver.JRRptServer();
    // initialize the RptServer.
    // at least the property reporthome should be set.
    rptServer.init(System.getProperties());
    rptServer.start();