I created a simple Java / JSP web application and added a basic Scala servlet. Everything works, and I included the Scala file and web.xml below. How can I change my little coaching servlet so that I can query the MySql table and create the HTML <table> ... </table>. By the way, I'll look at the elevator later. My plan for now is to add some new Scala servlets to an existing web application.
ScalaTrainer.scala
package com.mdm.h4
import javax.servlet.http. {HttpServlet,
HttpServletRequest => HSReq, HttpServletResponse => HSResp}
class ScalaTrainer extends HttpServlet
{
def html =
<html>
<head>
<title> Hello Scala </title>
</head>
<body>
<p style = "text-align: center"> This is 100% pure Scala. </p>
<p> It now
{currentDate}
</p>
<p> My name is
{name}
and I'm learning
{language}.
</p>
</body>
</html>
def name = "Mike"
def language = "Scala"
def currentDate = java.util.Calendar.getInstance (). getTime ()
override def doGet (req: HSReq, resp: HSResp) {
resp.getWriter (). print (html)
}
}
web.xml
<? xml version = "1.0" encoding = "UTF-8"?>
<web-app xmlns = "http://java.sun.com/xml/ns/javaee"
xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version="2.5">
<servlet>
<display-name>trainer</display-name>
<servlet-name>ScalaTrainer</servlet-name>
<servlet-class>com.mdm.h4.ScalaTrainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ScalaTrainer</servlet-name>
<url-pattern>/trainer</url-pattern>
</servlet-mapping>
</web-app>
anon