1

As an experiment in scala I want to set up a basic website with scala as a server side language. This would not carry out many interactive tasks - it would simply write and distribute HTML in response to HTTP requests.

I don't know much about how the piping of web servers works, but I've written lots of HTML, CSS, JS and PHP and I envisage this working much like the PHP back end in wordpress - the client sends an HTTP request for a page such as example.wordpress.com/2012/06/18/example_blog and the PHP on the server compiles an HTML web page and returns it to the user.

Although I'm open to suggestions, I'd rather not use a full blown framework such as Lift as I'm trying to build from the ground up. I'm only interested in the very basic task of taking an HTTP request as input and outputting an HTTP response.

2 Answers 2

3

Usually you'd take a Java EE server and implement a Servlet.

Here is one:

package myservlet

import javax.servlet.http._

class Servlet extends HttpServlet {
  /** Servlet's main method. */
  protected def welcome (request: HttpServletRequest, response: HttpServletResponse): Unit = {
    response.getWriter.write ("hi")
  }
  override def doGet (request: HttpServletRequest, response: HttpServletResponse): Unit = welcome (request, response)
  override def doPost (request: HttpServletRequest, response: HttpServletResponse): Unit = welcome (request, response)
}

Then you'd mention it in web.xml as usual:

<servlet><servlet-name>MyServlet</servlet-name>
  <servlet-class>myservlet.Servlet</servlet-class></servlet>
<servlet-mapping><servlet-name>MyServlet</servlet-name>
  <url-pattern>/</url-pattern></servlet-mapping>

Refer to any Java Servlet tutorial for details.

2

You may not want to deal with Java EE and the whole servlet thing, especially if you don't come from the "Java world".

There are some really lightweight HTTP toolkits in Scala like Blueeyes or Play mini but my favorite is definitely Unfiltered

EDIT: A more complete answer on this thread Scala framework for a Rest API Server?

1
  • 1
    I strongly second this answer. Just try out unfiltered, most likely you will be very happy. Jun 19, 2012 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.