BackPrevious Page Next PageNext

Using the Server API

This section shows using JReport Server API to achieve specific goals.

The HTTP methods GET and POST are available for almost all of JReport commands. The following is an example of using the POST method in Java program:

URL url = new URL("http://jrserver:8888");
URLConnection uc = url.getConnection();
if (uc instanceof HttpURLConnection) {
  HttpURLConnection huc = (HttpURLConnection)uc; 
  //set use POST method.
  huc.setRequestMethod("POST");
  huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  huc.setDoOutput(true);
//write the HTTP query to the output stream. OutputStreamWriter writer = new OutputStreamWriter(huc.getOutputStream()); writer.write("jrs.cmd=jrs.get_subnodes"); writer.close(); huc.getHeaderField(0);
//get the response content from the server. InputStream inStream = uc.getInputStream(); if (inStream != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); String inputLine; while (null != (inputLine = reader.readLine())) { System.out.println(inputLine); } } }

When using the Server API to perform tasks on resources in the server resource tree, you need to specify the full path of the resources in the code. Below are the rules:

Pick a task from below:

BackPrevious Page Next PageNext