Last active
December 10, 2015 12:38
-
-
Save bchristenson/4436025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test; | |
| import java.io.IOException; | |
| import javax.servlet.ServletException; | |
| import javax.servlet.http.HttpServlet; | |
| import javax.servlet.http.HttpServletRequest; | |
| import javax.servlet.http.HttpServletResponse; | |
| import org.jruby.CompatVersion; | |
| import org.jruby.embed.LocalContextScope; | |
| import org.jruby.embed.ScriptingContainer; | |
| public class JRubyEncodingServlet extends HttpServlet { | |
| public static void main(String[] args) { | |
| // Initialize the scripting container | |
| ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); | |
| // Set the compatibility version to 1.9, for proper UTF-8 support | |
| container.setCompatVersion(CompatVersion.RUBY1_9); | |
| container.runScriptlet("# encoding: utf-8\nputs 'π'"); | |
| container.runScriptlet("# encoding: utf-8\nputs 'π'.bytes.to_a.inspect"); | |
| // Prints: | |
| // π | |
| // [207, 128] | |
| } | |
| @Override | |
| protected void doGet(HttpServletRequest request, HttpServletResponse response) | |
| throws ServletException, IOException { | |
| // Initialize the scripting container | |
| ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD); | |
| // Set the compatibility version to 1.9, for proper UTF-8 support | |
| container.setCompatVersion(CompatVersion.RUBY1_9); | |
| container.runScriptlet("# encoding: utf-8\nputs 'π'"); | |
| container.runScriptlet("# encoding: utf-8\nputs 'π'.bytes.to_a.inspect"); | |
| // Prints: | |
| // ? | |
| // [63] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment