title: Read file utf-8, process and JSP
body: <p>I've got these files:</p>
  
  <p>in2.txt:</p>
  
  <pre><code>Hello
  ñuñííòúçç ùùù
  
  uíúgfl
  </code></pre>
  
  <p>Correct output (I obtain it in Eclipse (Linux)):</p>
  
  <pre><code>Hello
  ñuñííòúçç ùùù
  
  uíúgfl
  4 ís lèss thàn síx.
  </code></pre>
  
  <p>Notice that:</p>
  
  <ul>
  <li><p>The input (file) and the output have 'ñ', 'í',...</p></li>
  <li><p>'4' (in the output) is the number of lines of the input (file).</p></li>
  <li><p>The output has the characters 'í', 'è',...</p></li>
  </ul>
  
  <p>In a JSP file I want to get the correct output (at OpenShift.com), with a process. So, I need to improve my files (JAVA and JSP). So, the JSP file should show me the correct output (also if I redirect the process to out2.txt). Currently I get '?' or another strange characters. Also I've tried, unsuccessful:</p>
  
  <pre><code>PrintStream out = new PrintStream(System.out, true, "UTF-8");
  out.print(content);
  </code></pre>
  
  <p><strong>EDIT:</strong> My JSP file:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01   Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;&lt;/head&gt;&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8"&gt;
  &lt;title&gt;Try 2&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;% ProcessBuilder pb = new ProcessBuilder("bash", "-c", "java fileReader2");
         Process process = pb.start();
         // Process process = Runtime.getRuntime().exec("java fileReader2");
         while (process.waitFor()!=0){}; 
         InputStream shellIn = process.getInputStream();
         Writer writer = new StringWriter();
         int num=1;
         char[] buffer=new char[num];
         try { 
              Reader reader = new BufferedReader(new InputStreamReader(shellIn,"UTF-8"));
              int n;
              while ((n = reader.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
              }
         }
         finally{
               shellIn.close();
         }  
         String str = writer.toString();%&gt;
         &lt;form&gt;
         &lt;TEXTAREA NAME="textarea2" ROWS="15" COLS="1024" readonly="readonly"&gt;&lt;%=str %&gt;
         &lt;/TEXTAREA&gt;             
         &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Incorrect output at OpenShift.com:</p>
  
  <pre><code>Hello
  �u������� ���
  
  
  u��
  5 ?s l?ss th?n s?x.
  </code></pre>
  
  <p>Notice that:</p>
  
  <ol>
  <li><p>The characters 'gfl' are missing.</p></li>
  <li><p>I've obtained a line more (4+1=5).</p></li>
  <li><p>It appears strange characters and '?'s.</p></li>
  </ol>
  
  <p>My JAVA file:</p>
  
  <pre><code>import java.io.*;
  public class fileReader2{
  public static void main (String argsv[]){
  try{
     FileInputStream fis = new FileInputStream("in2.txt");
     String content="";
     InputStreamReader isr = new InputStreamReader(fis,"utf8");         
     BufferedReader br = new BufferedReader(isr);       
     String line; 
     int i=0;     
     while((line = br.readLine()) != null){       
         i++;
         content=content.concat(line).concat("\n");
      }      
  
       PrintStream out = new PrintStream(System.out, true, "UTF-8");
       out.print(content);
  
       if (i&lt;6){
          System.out.print(i+" ís lèss thàn síx.");
       }
       fis.close();
     }catch(Exception e1){} 
  }
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong> I found:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/14353342/change-uriencoding-in-openshift-jboss-as-7">Change URIEncoding in OpenShift JBoss AS 7</a></p></li>
  <li><p><a href="https://developer.jboss.org/message/643825" rel="nofollow noreferrer">https://developer.jboss.org/message/643825</a></p></li>
  </ul>
  
  <p>My standalone.xml is at '.../jbossas/standalone/configuration', and contains:</p>
  
  <pre><code>...
  &lt;/extensions&gt; 
  -&lt;system-properties&gt; 
     &lt;property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/&gt;
  &lt;/system-properties&gt;
  ...
  </code></pre>
  
  <p>I added 2 new properties in this XML file, but nothing occurs, for now. I didnt't find the file domain.xml (and either '.openshift/action-hooks/pre_start_jbossas-7').</p>
  
  <p><strong>Edit (24 APR):</strong> I've created a new CLASS file, with this future String (Java code), or as a example:</p>
  
  <pre><code>String s= "\u00F1ñ"
  ... // Code 
  </code></pre>
  
  <p>This futurist String has 7 characters. I want to see this output in a JSP (a process calls to my CLASS file). As I told you, I've created a new CLASS file, with only a char ('ñ'). In my JSP file I obtain:</p>
  
  <pre><code>241
  \u00F1
  </code></pre>
  
  <p>I wish:</p>
  
  <pre><code>241
  ñ
  </code></pre>
  
  <p>NOTE: 241 is %d of 'ñ'.</p>
  
  <p>I intend to do that, transforming all characters to UTF-8, but not a false unicode ("\uXXXX"), for example. I need ideas.</p>
  
  <p><strong>Edit (28 APR):</strong> My final objective is with JLex (an example code):</p>
  
  <pre><code>import java.io.*;
  import java.lang.*;
  %%
  %{
  public static void main (String argv [])
  throws java.io.IOException {
  if (argv.length != 1) {
  System.out.println("Usage:");
  System.out.println("\tjava fileReader filename.txt");
  return ;
  } else {
  String fInName = argv [0];
  if (!fInName.endsWith(".txt")) fInName = fInName + ".txt";
  FileInputStream input = new FileInputStream(fInName);
  //Create lexical analyzer
  fileReader yy = new fileReader (input);
  //Process input file
  while (yy.yylex()!=-1);
  // Show stats
  }
  } //End main
  %}
  %class fileReader
  %unicode
  %line
  %eof{
    if ((yyline+1)&lt;6){
       System.out.println();
       System.out.print((yyline)+" ís lèss thàn síx.");
    }
  %eof}
  %integer
  %state 
  break=[\r\n]
  %%
  &lt;YYINITIAL&gt;{break} { System.out.print(yytext()); }
  &lt;YYINITIAL&gt;. { System.out.print(yytext()); }
  </code></pre>
  
  <p>At OpenShift.com I obtain this:</p>
  
  <pre><code>Proxy Error
  The proxy server received an invalid response from an upstream server.
  The proxy server could not handle the request GET /1x2/try_utf8.jsp.
  
  Reason: Error reading from remote server
  
  
  
  --------------------------------------------------------------------------------
  
  Apache/2.2.15 (Red Hat) Server at jlex1x2-uocpfc.rhcloud.com Port 80
  </code></pre>
  
  <p>At Linux it runs OK. How to solve this?</p>