Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 248265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:19:43+00:00 2026-05-11T21:19:43+00:00

I am pretty new to jruby and java and want to create a servlet

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:19:43+00:00Added an answer on May 11, 2026 at 9:19 pm

    I got some external help and can present a proper solution. To offer a complete but simple set-up I use a html file for the data input (but this could be done in jetty as done above).

    <?xml version="1.0" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Data input</title>
    </head>
    <body>
    <form action="http://localhost:8080/" method="post">
      <textarea name="input" cols="4" rows="20"></textarea>
      </p>
      <input type="submit" value=" Send"/>
    </form>
    </body>
    </html>
    

    The jruby part is confusingly simple ;):

    require 'java'
    
    Dir["./Java/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.http.HttpServlet'
    include_class 'org.mortbay.jetty.Server'
    include_class 'org.mortbay.jetty.servlet.Context'
    include_class 'org.mortbay.jetty.servlet.ServletHolder'
    
    def main
      server = Server.new(8080)
      context = Context.new(server, '/', 0)
      servlet = TestServlet.new()
      holder = ServletHolder.new(servlet)
      context.addServlet(holder, '/')
      server.start()
    end
    
    class TestServlet < HttpServlet
    
      def doPost(request, response)
        input = request.getParameter('input')
        response.writer.println("
        <html>
         <head><title>Output</title></head>
         <body>
         Raw input: <pre>#{input}</pre> 
         </body>
        </html>")
        request.handled = true
      end
    
    end
    
    main
    

    To harvest data that was sent via GET simply define doGet in similar manner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 213k
  • Answers 213k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer MSBuild (what VisualStudio uses to build) can provide you with… May 12, 2026 at 10:39 pm
  • Editorial Team
    Editorial Team added an answer The 404 handler specified in the web.config only works for… May 12, 2026 at 10:38 pm
  • Editorial Team
    Editorial Team added an answer Look into using the client PageRequestManager events to save/restore state… May 12, 2026 at 10:38 pm

Related Questions

I am pretty new to php, but I am learning! I have a simple
I am pretty new to VB.NET - and I'm struggling to convert the signature
I am pretty new to the Unity Application Block and am a little stuck
I am pretty new to C# and .NET and I'm strugling a little with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.