Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit:</strong> check <a href="http://scalate.fusesource.org/index.html" rel="noreferrer">http://scalate.fusesource.org/index.html</a>: <em>Scala Template Engine: like JSP without the crap but with added Scala coolness</em>. I just stumbled upon this while checking the #scala twitter feed.</p> <hr> <p>You can have a look at <a href="http://github.com/alandipert/step" rel="noreferrer">http://github.com/alandipert/step</a>. It looks like an active project with just enough to let you write Scala code mixed with xhtml code. Whether you can <em>script like PHP</em>, I don't know. One of the difference is that with JSP/PHP, you include a program inside an HTML page where as with <code>step</code> you include some <code>xml</code> into a Scala file. </p> <p>There is going to be a bit of a learning curve with Scala and <a href="http://code.google.com/p/simple-build-tool/" rel="noreferrer"><code>sbt</code></a> but I think it's worth it to take advantage of Scala.</p> <p>The other thing you can do is to write a custom JSP tag that lets you run some Scala code through the interpreter. I did a proof of concept and this seems to work:</p> <pre><code>/** * Proof of concept, you can run Scala code in a JSP tag. * Works with jetty and sbt. */ class ScalaScriptTag extends BodyTagSupport { override def doAfterBody():Int = { try { val settings = new Settings(str =&gt; println(str)) // interpreter classloader does not seem to pick up classes from the parent settings.classpath.value = "lib_managed/compile/jsp-api-2.1-6.1.14.jar;" + "lib_managed/compile/servlet-api-2.5-6.1.14.jar" var i = new Interpreter(settings) { override def parentClassLoader():ClassLoader = { return Thread.currentThread().getContextClassLoader(); } } i.bind("pageContext", "javax.servlet.jsp.PageContext", pageContext) val source = Source.fromString(getBodyContent.getString) for (line &lt;- source.getLines) { i.interpret(line) } } catch { case ioe: IOException =&gt; throw new JspException(ioe.getMessage()) } Tag.SKIP_BODY } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload