I am pretty new to jruby and java and want to create a servlet in jruby while using jetty as web server. I am not sure if I am on the right way with the following code which shows the input form so far. I guess I have to extend now the HttpServlet class to handle the posted data but I don't know how to do this in this case and if it is okay to do this in the same script.
require 'java'
Dir["./jetty-6.1.18/lib/*jar"].each { |jar| require jar }
Dir["./Java/lib/jsdk2.1/javax/*jar"].each { |jar| require jar }
include_class 'javax.servlet.ServletException'
include_class 'javax.servlet.http.HttpServlet'
include_class 'javax.servlet.http.HttpServletRequest'
include_class 'javax.servlet.http.HttpServletResponse'
include_class 'org.mortbay.jetty.Server'
include_class 'org.mortbay.jetty.handler.AbstractHandler'
include_class 'org.mortbay.jetty.servlet.Context'
include_class 'org.mortbay.jetty.servlet.ServletHolder'
def main
handler = Handler.new
server = Server.new(8080)
server.setHandler(handler)
server.start()
end
class Handler < AbstractHandler
def handle(target, request, response, dispatch)
response.setContentType("text/html")
response.setStatus(HttpServletResponse::SC_OK)
response.getWriter().print('
<form action="RequestProcessing" method="post" enctype="multipart/form-data">
<p>Select a file:<br>
<input name="file" type="file" size="20" maxlength="1000" accept="text/*">
</p>
<input type="submit" value=" Send"/>
</form>')
request.setHandled(true)
end
end
class RequestProcessing < HttpServlet
# So what do we do here?
end
main
I would be thankful for any hints. Many thanks in advance!