
HIP-HOP od THE YELLOW SPORT SHOES , 57.0 x 57.0 cm, oil timber , 2009
package com.muchsoft.scala.servletsThe looks around as Java, right? Not quite: When importing we can make Redefinitions that
import javax.servlet.http.HttpServlet import javax.servlet.http
. HttpServletRequest {=> Request, HttpServletResponse
=> Response}
MeinErstesScalaServlet class extends HttpServlet {override def
doGet (request: Request, response: response) {
val output =
\u0026lt;html>
\u0026lt; head> Scala \u0026lt;title> Hello \u0026lt;/ title> \u0026lt;/ head>
\u0026lt;body>
\u0026lt;h1> Scala Hello World \u0026lt;/ h1>
\u0026lt;/ body>
\u0026lt;/ html>
response.getWriter (). Print (output)
}}
override before the method definition is mandatory, also a key word and no annotation. The return type of method doGet ()
is not specified and thus corresponds to the Java
void. For Scala we had before the opening curly Clamp methods : Unit =
can write. doGet ()
we put the issue on XML literal
(as non-modifiable value
val; with var
scale variables, one tries to avoid in functional languages). This XML literal, we write as usual in the output stream of the Response object. The type of output
is scala.xml.Elem
. WEB-INF/classes
. The Scala standard library scala-library.jar
be delivered (from the Scala installation directory) must be in WEB-INF/lib
with. In WEB-INF/web.xml
we map the class
com.muchsoft.scala.servlets.MeinErstesScalaServlet to the URL "hallo.scala. After you deploy (deployment), for example in Tomcat or GlassFish the servlet in the Web browser will be invoked with the URL http://localhost:8080/halloscala/hallo.scala . -api.jar
or from the GlassFish directory javaee.jar
embed as an external library. MeinZweitesScalaServlet class extends HttpServlet {
def output =
\u0026lt;html>
\u0026lt;head> \u0026lt;title> Scala Hello \u0026lt;/ title> !; \u0026lt;/ head>
\u0026lt;body>
\u0026lt;h1> Scala Hello World \u0026lt;/ h1>
\u0026lt;p> time on the server: {now} \u0026lt;/ p>
\u0026lt;/ body>
\u0026lt;/ html>
def now = new java.util.Date
override def doGet (request: Request, response: response) {.
response.getWriter () print (output)
}}
output
is now a function outside of doGet ()
, which relies on the function now
to output a current time stamp. Both functions are defined without parameters brackets and must be called without parentheses. If we had defined the parameters of functions with empty parentheses, we could have chosen it when you call us not if we write down the brackets or. It has been the convention developed to omit the brackets in the definition, if a function, no side effects (side effects) has. MeinDrittesScalaServlet class extends HttpServlet {JSF, Wicket
def output (username: String) =
\u0026lt;html>
\u0026lt;head> \u0026lt;title> Scala Hello World \u0026lt;/ title> \u0026lt;/ head>
\u0026lt;body> ;
\u0026lt;h1> Hello {username} \u0026lt;/ h1>
\u0026lt;p> time on the Server: {now} \u0026lt;/ p>
\u0026lt;form method="get" action="hallo3.scala">
\u0026lt;p> What's your name?
\u0026lt;input name="benutzer"
/> \u0026lt;input type="submit" value="Submit"
/> \u0026lt;/ p>
\u0026lt;/ form>
\u0026lt;/ body>
\u0026lt; / html>
def now = new java.util.Date
override def doGet (request: Request, response: response) {val
param = getParameter request "user"
val = username
if ((param == null) is mapped in web.xml
to the URL "hallo3.scala" may be the call in the local application server with
http://localhost:8080/halloscala/hallo3.scala?benutzer=Thomas
.
In practice, you probably do not servlets programming more direct, but a framework like Struts
,
etc. . Insert We see here but well, how easy it into existing Java-Scala (web) applications can integrate. And if you want to develop web applications really functional, you can use the Scala Lift
framework.
JavaScript, and JavaScript as the programming language has been - despite Objektbasierung and functional aspects - not taken seriously. With Web 2.0
and Ajax NTLMv2 proxy server, since the Eclipse 3.5 can not be directly supported. In addition to the proper setup to add the proxy address and authentication data
under Preferences> General> Network Connections in the file must eclipse.ini (in the Eclipse program directory) at the end
-Dorge . eclipse.ecf.provider.filetransfer.excludeContributors = org.eclipse.ecf.provider.filetransfer.httpclient it was in Eclipse 3.5 in the above Preferences page also necessary in the "Active provider" set to "Native". In Eclipse 3.5.1 works set to "Manual".