14 September 2011

How to handle parameters from GET request in jetty ?

Solution based on  Jetty 6.1.x *

It quite easy, In your  handle method

 public void handle(String target, HttpServletRequest request, HttpServletResponse response, int arg) throws IOException, ServletException {
  String myCoolParameter = request.getParameter(" myCoolParameter ");
 
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
  response.getWriter().println("Your paramater is:>" + myCoolParameter );
((Request)request).setHandled(true);
} 

 If you have more parameter you just add another   getParameter(name) where name is a name of parameter
so for example
http://eclispe.screw.up.jetty.seven/example.html?eclipseiscrap=true&whyihateeclipse=because is clumsy
  request.getParameter("eclipseiscrap");
  request.getParameter("whyihateeclipse");



*I have no idea is it works on jetty 7.x+ because I was unable to install and run it as embedded server.
 Eclipse Foundation mess up badly  with Jetty again.Eclipse really should change name to Clumsy.