tags:

views:

23

answers:

3

Hello to all, I wonder how cn i pass a request parameter of a servlet as a parameter to another java file of my web app that doesm't have POST and GET methods?

Thanks in advance

Antonis

+1  A: 

What's the problem with someObject.someMethod(request, response) ?

Christoffer Hammarström
He told he just need to send param to another class while someMethod(request, response) are servlets or something extends it.
Truong Ha
+3  A: 

Simply by getting the request parameter from the HttpServletRequest object, and using it as a parameter.

void doGet(HttpServletRequest req,
                     HttpServletResponse resp)
              throws ServletException,
                     java.io.IOException {

  String param = req.getParameter("name_of_your_param");
  new YourOtherClass().yourOtherMethod(param);
  //implement the rest to return a response
}

I'm excluding obvious things like input validation on the parameter (e.g. if the http client didn't send the parameter in the request, the result of getParameter is null) and sending the response.

Please takes some time to become familiar with the Servlet API and refer to it whenever you are curious how to do something with your Servlets and Request/Response objects: http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/index.html

whaley
+1  A: 

Your request always passes through a Servlet, so:

  • extract the needed parameters there
  • pass them as arguments to the helper

There is another option - to store what you need in a ThreadLocal variable, because each request is handled in a separate thread, but that's to be avoided.

Bozho
Thank you all so much
Antonis