I have below PHP function code which echoes the server's response.
PHP Code
function printMessage($errMsg){
$color='#ffffff';
echo "<table style=>";
echo "<tr bgcolor='".$color."'> ".randomFun($errMsg, 0)."</tr>";
echo "</table>";
}
I have to migrate the same in Scala(new with Scala).
Scala Code
def printMessage(errMsg: String): Unit = {
val color = "#ffffff"
val formattedErrMsg = randomFun(errMsg, 0)
println(
s"""<table style="">
| <tr bgcolor='$color'>
| $formattedErrMsg
| </tr>
|</table>
""".stripMargin
)
}
Well, I am unsure if this will behave the same way as the echo in PHP. Looking for a way in Scala to echo the response on server as in PHP.
No, the
printlnfunction will not work the same way asechoin php. If you want to write a service in Scala, then you need to use the appropriate frameworks.For example:
Play Framework - https://www.playframework.com/
Akka-http - https://doc.akka.io/docs/akka-http/current/introduction.html
http4s - https://http4s.org/v0.20/service/
println()- this is a simple function to output a message to the console.