title: yaz4j Url parameters for connection to library
body: <blockquote>
    <p>I get excamples from
    <a href="https://github.com/indexdata/yaz4j/tree/master/examples/zgate" rel="nofollow noreferrer">https://github.com/indexdata/yaz4j/tree/master/examples/zgate</a>  for get
    library data. In excample have help text in commentary:</p>
    
    <p><strong>/* For dinosaur search use: ?zurl=z3950.loc.gov:7090/voyager&amp;query=@attr 1=7
    0253333490&amp;syntax=usmarc*/</strong></p>
    
    <p>And i use this for url and get data from library.This url is dvided
    into 3 pars: <strong>1)zurl=z3950.loc.gov:7090/voyager 2)query=@attr 1=7
    0253333490 3)syntax=usmarc</strong>    ; I dont know how i can get this
    parameters for  send. In this code used
    <strong>zurl=z3950.loc.gov:7090/voyager</strong>  or <strong>query=@attr 1=7 0253333490</strong> or <strong>syntax=usmarc</strong>. How i must define how must be query format, or syntax
    format or zurl format for sendind. Where i can for excample
    z3950.loc.gov:7090/voyager, how i can know its format. And @attr 1=7
    0253333490 its stange query format and etc.Please help for geting this
    format.  And this is  my  servlet code code which gets this
    parameters.</p>
  </blockquote>
  
  <pre><code>package web;/*
   * Copyright (c) 1995-2010, Index Data
   * All rights reserved.
   * See the file LICENSE for details.
   */
  
  import org.yaz4j.Connection;
  import org.yaz4j.Record;
  import org.yaz4j.ResultSet;
  import org.yaz4j.exception.ZoomException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  
  
  /**
   *
   * @author jakub
   */
  public class ZgateServlet extends HttpServlet {
  
    @Override
    public void init() throws ServletException {
      System.out.println("Zeta: java.library.path=" + System.getProperty("java.library.path"));
      System.out.println("Zeta: LD_LIBRARY_PATH=" + System.getenv("LD_LIBRARY_PATH"));
    }
  
    @Override
    /*
     * For dinosaur search use: ?zurl=z3950.loc.gov:7090/voyager&amp;query=@attr 1=7 0253333490&amp;syntax=usmarc
     *
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
      String zurl = request.getParameter("zurl");
      if (zurl == null || zurl.isEmpty()) { response.sendError(400, "Missing parameter 'zurl'"); return; }
  
      String query = request.getParameter("query");
      if (query == null || query.isEmpty()) { response.sendError(400, "Missing parameter 'query'"); return; }
  
      String syntax = request.getParameter("syntax");
      if (syntax == null || syntax.isEmpty()) { response.sendError(400, "Missing parameter 'syntax'"); return; }
  
      int maxrecs=10;
      if (request.getParameter("maxrecs") != null &amp;&amp; !request.getParameter("maxrecs").isEmpty()) {
        try {
          maxrecs = Integer.parseInt(request.getParameter("maxrecs"));
        } catch (NumberFormatException nfe) {
          response.sendError(400, "Malformed parameter 'maxrecs'");
          return;
        }
      }
  
      response.getWriter().println("SEARCH PARAMETERS");
      response.getWriter().println("zurl: " + zurl);
      response.getWriter().println("query: " + query);
      response.getWriter().println("syntax: " + syntax);
      response.getWriter().println("maxrecs: " + maxrecs);
      response.getWriter().println();
  
      Connection con = new Connection(zurl, 0);
      con.setSyntax(syntax);
      try {
        con.connect();
        ResultSet set = con.search(query, Connection.QueryType.PrefixQuery);
        response.getWriter().println("Showing " + maxrecs + " of " +set.getHitCount());
        response.getWriter().println();
        for(int i=0; i&lt;set.getHitCount() &amp;&amp; i&lt;maxrecs; i++) {
          Record rec = set.getRecord(i);
          if (rec == null) continue;
          response.getWriter().print(rec.render());
        }
      } catch (ZoomException ze) {
        throw new ServletException(ze);
      } finally {
        con.close();
      }
    }
  
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    }
  
    @Override
    public String getServletInfo() {
      return "Zeta search engine servlet";
    }
  }
  </code></pre>